题目链接:http://acm.nyist.net/JudgeOnline/problem.php?pid=2
#include <stdio.h> #include <stack> #include <map> #include <queue> #include <math.h> #include <stdlib.h> #include <vector> #include <algorithm> #include <iostream> #include <string> using namespace std; string s; int main() { int t; scanf("%d",&t); while(t--) { stack<char> ans;///模拟进出站 int i; cin>>s; for(i=0; i<s.size(); i++) { if(s[i]=='['||s[i]=='(') ans.push(s[i]); else if(ans.size()) { if(s[i]==')'&&ans.top()=='('||s[i]==']'&&ans.top()=='[') { ans.pop(); } else { break; } } else break; } if(i==s.size()&&ans.empty()) printf("Yes "); else printf("No "); } return 0; }