#include<stdio.h>
#include<string.h>
#include<vector>
#include<iostream>
using namespace std;
typedef vector <int> piles;
int main(){
piles pile;
int testcase,i,mark;
char s[150];
scanf("%d",&testcase);
getchar();
while(testcase--){
pile.clear();
mark=1;
gets(s);
for(i=0;mark!=0&&i<strlen(s);i++){
if(s[i]=='(') pile.push_back(1);
else if(s[i]=='[') pile.push_back(2);
else if(s[i]==')'){
if(pile.empty()==true) mark=0;
else if(pile[pile.size()-1]==1) pile.pop_back();
else if(pile[pile.size()-1]==2) mark=0;
}
else{
if(pile.empty()==true) mark=0;
else if(pile[pile.size()-1]==1) mark=0;
else pile.pop_back();
}
}
if(pile.empty()!=true) mark=0;
if(mark==1) printf("Yes\n");
else printf("No\n");
}
return 0;
}
uva 673
最新推荐文章于 2022-03-19 16:54:02 发布