提交时间:2023-08-22 15:58:13
运行 ID: 99272
#include<iostream> #include<stack> #include<string> using namespace std; int main (){ string n; stack <int> stk; cin >> n; for (int i = 0;i < n.size();i ++){ if (n[i] == '('){ stk.push(1); } else if (n[i] == ')'){ if (stk.empty() ){ cout << "NO"; return 0; } else { stk.pop() ; } } } if (!stk.empty() ) cout << "NO"; else cout << "YES"; return 0; }