提交时间:2023-08-22 16:27:29

运行 ID: 99390

#include <bits/stdc++.h> using namespace std; signed main() { string s; int cnt = 0; cin >> s; if(s[0]==')') { cout << "NO"; exit(0); } for(int i = 0; i <= s.length()-2; i++) { if(s[i]=='(')cnt++; else if(s[i]==')')cnt--; if(cnt<0) { cout << "NO"; exit(0); } } cout << ((cnt==0)?"YES":"NO"); return 0; }