代码如下:
#include <bits/stdc++.h>
using namespace std;
stack<char> s;
string str;
int main(){
ios::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
cin >> str;
int len=str.size();
for(int i=0;i<len;i++){
if(str[i]=='('){
s.push(str[i]);
}else{
if(str[i]==')'){
if(s.top()=='('){
s.pop();
}
}
}
}
if(!s.empty()){
cout << "NO";
}else{
cout << "YES";
}
return 0;
}