栈下溢或者最后不为空,则输出No
gets在uva不能用,只好改成cin.getline了
#include <cstdio>
#include <cstring>
#include <vector>
#include <queue>
#include <iostream>
using namespace std;
#define DEBUG
const int maxn=128+5,maxv=26;
int t;
char s[maxn];
char q[maxn];
void solve(){
int t=0;
int len=strlen(s);
for(int i=0;i<len;i++){
if(s[i]=='('||s[i]=='[')
q[t++]=s[i];
else if(s[i]==')'||s[i]==']'){
if(t==0){cout<<"No\n";return;}
char c=q[t-1];t--;
// printf("%c %c\n", s[i],c);
if(s[i]==')'&&c=='('){}
else if(s[i]==']'&&c=='['){}
else{cout<<"No\n";return;}
}
}
if(t==0)
cout<<"Yes\n";
else
cout<<"No\n";
}
int main(){
#ifdef DEBUG
freopen("in.txt", "r", stdin);
freopen("out.txt", "w", stdout);
#endif
cin>>t;
getchar();
while(t--){
cin.getline(s,maxn+10);
// cout<<s;
solve();
}
#ifdef DEBUG
fclose(stdin);
fclose(stdout);
#endif
return 0;
}