#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
char s[100];
char a[100];
int main()
{
int i,j,k,f,top,len;
while(gets(s) != '\0')
{
len = strlen(s);
top = 0;
f = 0;
for(i = 0; i < len; i ++)
{
if(s[i] == ')')
{
if(top == 0)
{
f = 1;
break;
}
else
{
if(a[top - 1] == '(')
{
top --;
}
else
{
f = 1;
break;
}
}
}
else if(s[i] == '(')
{
a[top ++] = '(';
}
else if(s[i] == '}')
{
if(top == 0)
{
f = 1;
break;
}
else
{
if(a[top - 1] == '{')
{
top --;
}
else
{
f = 1;
break;
}
}
}
else if(s[i] == '{')
{
a[top ++] = '{';
}
else if(s[i] == ']')
{
if(top == 0)
{
f = 1;
break;
}
else
{
if(a[top - 1] == '[')
{
top --;
}
else
{
f = 1;
break;
}
}
}
else if(s[i] == '[')
{
a[top ++] = '[';
}
}
if(top != 0 || f == 1)
printf("no\n");
else
printf("yes\n");
}
return 0;
}
标签:2134,++,top,之栈,len,else,break,--,SDUT From: https://blog.51cto.com/u_15965659/6056630