比较简单的模拟
代码:
#include<cstdio>
#include<cstring>
#include<iostream>
using namespace std;
const int maxn=200;
char stack[maxn],top=0;
int main()
{
int cas,flag;
scanf("%d",&cas);
char str[maxn];
getchar();
while(cas--)
{
gets(str);
top=flag=0;
for(int i=0;i<strlen(str);i++)
{
if(!top||str[i]=='['||str[i]=='(')
stack[++top]=str[i];
else if(str[i]==']'&&stack[top]=='['||str[i]==')'&&stack[top]=='(')
top--;
else
{
flag=1;
break;
}
}
if(!flag&&top==0)
printf("Yes\n");
else
printf("No\n");
}
return 0;
}