题目描述
输入
输出
样例输入1
a(cc())bbb()@
样例输出1
YES
样例输入2
a(cc()bbb()@
样例输出2
NO
做法1
#include <bits/stdc++.h>
using namespace std;
int main(void) {
string s;
cin >> s;
int depth = 0;
bool flag = true;
for (const auto &c: s) {
if (c == '(') {
++depth;
} else if (c == ')') {
--depth;
if (depth < 0) {
flag = false;
break;
}
} else if (c == '@') {
break;
}
}
if (depth > 0) flag = false;
cout << (flag ? "YES" : "NO") << endl;
return 0;
}