用栈模拟
#include<cstdio>
#include<algorithm>
#include<cstring>
#include<iostream>
using namespace std;
int stk[1000];
char s[1000];
int main()
{
//freopen("out.txt","w",stdout);
int n;
cin>>n;getchar();
while(n--)
{
gets(s);
int l=strlen(s);
if(l==0)
{
puts("Yes");continue;
}
else
{
int idx=0;bool f=true;
for(int i=0;i<l;i++)
{
if(s[i]=='(')stk[idx++]=1;
if(s[i]=='[')stk[idx++]=2;
if(s[i]==')')
{
if(stk[idx-1]==1)idx--;
else f=false;
}
if(s[i]==']')
{
if(stk[idx-1]==2)idx--;
else f=false;
}
}
if(idx!=0)f=false;
if(f)puts("Yes");
else puts("No");
}
}
}