给定一个只包括 '(',')','{','}','[',']' 的字符串,判断字符串是否有效。
有效字符串需满足:
1. 左括号必须用相同类型的右括号闭合。
2. 左括号必须以正确的顺序闭合。
3. 注意空字符串可被认为是有效字符串。
//#include <algorithm>
//#include <cmath>
//#include <iostream>
//#include <map>
//#include <queue>
//#include <stack>
//#include <string>
//#include <string.h>
//#include <vector>
//using namespace std;
//bool Ispair(char a, char b);
//
//int main(){
// string s = "";
// while(getline(cin, s)){
// if(s.empty()){
// cout << "true" <<endl;
// continue;
// }else{
// stack<char> st;
// st.push(s[0]);
// for(int i = 1; i < (int)s.size(); i++){
// if(!st.empty() && Ispair(st.top(),s[i])){
// st.pop();
// }else{
// st.push(s[i]);
// }
// }
// if(st.empty()){
// cout << "true" << endl;
// }else{
// cout << "false" << endl;
// }
// }
// }
// return 0;
//}
//
//bool Ispair(char a, char b){
// if(a == '(' && b == ')'){
// return true;
// }
// if(a == '[' && b == ']'){
// return true;
// }
// if(a == '{' && b == '}'){
// return true;
// }
// return false;
//}
**粗体** _斜体_ [链接](http://example.com) `代码` - 列表 > 引用
。你还可以使用@
来通知其他用户。