#include<stdio.h>
#include<string.h>
const int N = 150;
int match(char e[],int n)
{
if(n<0)
{
return 0;
}
char a[N];
int top = 0;
int i;
for(i = 0;i<n;++i)
{
if(e[i] == '('||e[i] == '{'||e[i] == '[')
{
a[top++] = e[i];
// printf("%c",a[top-1]);
}
if(e[i] ==')')
{
if(a[top-1]=='(')
{
top--;
}
else
return 0;
}
if(e[i] =='}')
{
if(a[top-1]=='{')
{
top--;
}
else
return 0;
}
if(e[i] ==']')
{
if(a[top-1]=='[')
{
top--;
}
else
return 0;
}
}
if(top == 0)
return 1;
return 0;
}
int main(){
char a[N];
scanf("%s",a);
int len = strlen(a);
if(match(a,len))
{
printf("1");
}
else
{
printf("0");
}
return 0;
}
括号匹配问题
最新推荐文章于 2025-05-23 17:35:25 发布