#include<iostream>
#include<stack>
#include<cstring>
using namespace std;
char str[10001];
int main(){
int T,flag;
cin>>T;
while(T--)
{
flag=1;
stack<char>s;
memset(str,0,sizeof(str));
cin>>str;
for(int i=0;str[i]!=0;i++){
if(str[i]=='('||str[i]=='['){
s.push(str[i]);
}
if(str[i]==')'){
if(s.size()&&s.top()=='(')
s.pop();
else{
flag=0;
break;
}
}
if(str[i]==']'){
if(s.size()&&s.top()=='[')
s.pop();
else{
flag=0;
break;
}
}
}
if((!flag)||s.size()) cout<<"No"<<endl;
else cout<<"Yes"<<endl;
}
return 0;
}
NYOJ-2 括号配对问题
最新推荐文章于 2019-01-05 21:23:04 发布