提交时间:2023-08-22 16:11:19

运行 ID: 99318

#include <bits/stdc++.h> using namespace std; int main(){ stack <char> stk; string a; cin>>a; for(int i = 0;i<a.size();i++){ if(a[i]==')'){ if(stk.size()==0||stk.top()!='('){ cout<<"NO"<<endl; return 0; } stk.pop(); } else if(a[i]=='('){ stk.push(a[i]); } else continue; } if(stk.size()>0){ cout<<"NO"<<endl; return 0; } cout<<"YES"<<endl; return 0; }