#include <stdio.h>
int IsPiPei(const char * p)
{
int counter=0;
while (*p)
{
if (*p=='(')
{
counter++;
}
else if (*p==')')
{
if(--counter<0)
{
return 0;//不匹配
}
}
p++;
}
if (counter)
{
return 0;//不匹配
}
else
{
return 1;
}
}
void main()
{
char * str="a()b()e)(";
if (IsPiPei(str))
{
printf("匹配成功!/n");
}
else
{
printf("匹配不成功!/n");
}
}