求助!代码如下
#include <bits/stdc++.h>
using namespace std;
int main() {
int n;
cin>>n;
getchar();
for(int i=1;i<=n;i++){
string s;
getline(cin,s);
stack<char>stk;
while(!stk.empty())stk.pop();
int f=1;
int x=s.size();
if(x==0){
cout<<"Yes\n";
continue;
}
for(int j=0;j<x;j++){
if(s[j]=='('){
stk.push('(');
}else if(s[j]=='[')
{
stk.push('[');
}else if(s[j]==')'){
if(stk.empty()){
f=0;
}
else{
if(stk.top()=='('){
stk.pop();
}else{
f=0;
}
}
}else if(s[j]==']'){
if(stk.empty()){
f=0;
}else{
if(stk.top()=='['){
stk.pop();
}else{
f=0;
}
}
}
}
if(f==1){
cout<<"Yes\n";
}else cout<<"No\n";
}
return 0;
}