水題
幾個注意點:
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;
}