题目描述:
题目思路:
1.水题
2.栈+模拟
3.坑在有空串
AC代码
1 #include <iostream> 2 #include <stack> 3 using namespace std; 4 5 int main(int argc, char *argv[]) 6 { 7 int t; 8 scanf("%d",&t); 9 getchar(); 10 while(t--) 11 { 12 string buf; 13 stack<char> s; 14 getline(cin,buf); 15 int len = buf.size(); 16 int i ,flag = 0; 17 for(i = 0;i < len;i ++) 18 { 19 if(buf[i] == '(' || buf[i] == '[') s.push(buf[i]) ; 20 else if(!s.empty() && s.top()=='('&&buf[i]==')') s.pop() ; 21 else if(!s.empty() && s.top()=='['&&buf[i]==']') s.pop() ; 22 else flag = 1; 23 } 24 if(!flag && !s.size()) cout<<"Yes"<<endl; 25 else cout<<"No"<<endl; 26 } 27 return 0; 28 }