题解 | #Problem E#
Problem E
https://www.nowcoder.com/practice/3bad4a646b5b47b9b85e3dcb9488a8c3
//debug了好久 #include <iostream> #include <stack> using namespace std; int main(){ int n; stack<char> op; cin>>n; while(n--){ string s; while(op.size()) op.pop(); cin>>s; for(int i = 0; i < s.size(); i ++){ if(s[i] == '(' || s[i] == '[' || s[i] == '{') op.push(s[i]); else if(op.size() && s[i] == ')' && op.top() == '(') op.pop(); else if(op.size() && s[i] == ']' && op.top() == '[') op.pop(); else if(op.size() && s[i] == '}' && op.top() == '{' ) op.pop(); else if(s[i] == '}' || s[i] == ']' || s[i] == ')'){ op.push(s[i]); } } if(op.empty()) puts("yes"); else puts("no"); } return 0; }