水题
几个注意点:
1. 可以用cnt来代替栈
2. 对于左括号与右括号 要分别处理
//P1739 表达式括号匹配
//2016.11.23
#include <cstdio>
#include <iostream>
using namespace std;
char c;
int cnt = 0; //用来代替栈
int main(){
while (scanf("%c", &c) == 1){
if (c == '@') break;
if (c == '(') cnt++;
if (c == ')') //注意! 要防止像这样的情况:))((
if (cnt > 0) cnt--;
else {
printf("NO");
return 0;
}
}
if (!cnt) printf("YES");
else printf("NO");
return 0;
}