#include <stdio.h>
#include <stdlib.h>
int match(int n)
{
char stack[100];
int top=-1;
int i;
char xp[10]={'(','(','(','(','(',')',')',')',')',')'};
for(i=0; i<n; i++)
{
if(xp[i]=='(')
{
top++;
stack[top]='(';
}
if(xp[i]==')')
{
if(top==-1)
{
return 0;
}
else
{
--top;
}
}
}
int j;
if(top==-1)return 1;
else return 0;
}
int main()
{
int n=10;
int x;
x=match(n);
printf("%d\n",x);
return 0;
}
用栈匹配字符“(“,“)“
最新推荐文章于 2022-05-06 17:28:20 发布