#include<iostream>
#include<stdio.h>
using namespace std;
int main()
{
char a[51],b[51];
int i,top;
while(gets(a)!=NULL)
{
top=-1;
for(i=0;a[i]!='\0';i++)
{
if(a[i]=='{'||a[i]=='['||a[i]=='(')
{
b[++top]=a[i];
}
else if(a[i]=='}')
{
if(b[top]=='{')
{
top--;
}
else
{
break;
}
}
else if(a[i]==']')
{
if(b[top]=='[')
{
top--;
}
else
{
break;
}
}
else if(a[i]==')')
{
if(b[top]=='(')
{
top--;
}
else
{
break;
}
}
}
if(top==-1 && a[i]=='\0')
cout<<"yes"<<endl;
else
cout<<"no"<<endl;
}
return 0;
}
SDUT OJ 数据结构实验之栈四:括号匹配
最新推荐文章于 2018-10-19 09:20:14 发布