表达式括号匹配(栈)

#include<cstdio>
#include<iostream>
#include<cmath>
#include<cstring>
#include<algorithm>
#include<string>
#define maxn 20
char c[256];
bool work(char c[256])
{ 
    int top=0,i=0;
    while (c[i]!='@') 
    {
        if (c[i]=='(') top++;
        if (c[i]==')') 
        {
           if (top>0) top--;
             else return 0;
        }
        i++;
    }
    if (top!=0) return 0;        
    else return 1;
}
int main()
{
    scanf("%s",c);   
    if (work(c)) printf("YES");
    else printf("NO");

    return 0;
}
原文地址:https://www.cnblogs.com/thx666/p/8324006.html