题目网址http://ybt.ssoier.cn:8088/problem_show.php?pid=1355
#include<iostream>
#include<cstdio>
#include<cstring>
using namespace std;
int top=0,s[1005],n,ans[100005];
char a[1005];
int panding(int q)
{
int len=strlen(a);
for(int i=0;i<len;i++)
{
if(a[i]=='('||a[i]=='['||a[i]=='{'||a[i]=='<')
{
top++;
s[top]=a[i];
}
if(a[i]==')')
{
if(s[top]=='(')]
top--;
else
return 0;
}
if(a[i]==']')
{
if(s[top]=='[')
top--;
else
return 0;
}
if(a[i]=='>')
{
if(s[top]=='<')
top--;
else
return 0;
}
if(a[i]=='}')
{
if(s[top]=='{')
top--;
else
return 0;
}
}
if(top==0)
return 1;
else
return 0;
}
int main( )
{
cin>>n;
for(int q=1;q<=n;q++)
{
memset(s,0,sizeof(s));
scanf("%s",a);
ans[q]=panding(q);
}
for(int i=1;i<=n;i++)
{
if(ans[i]==1)
cout<<"YES"<<endl;
else
cout<<"NO"<<endl;
}
return 0;
}