#include <iostream> #include <string.h> #include <algorithm> #include <stdio.h> #include <math.h> #include <map> #include <string> #include <set> #include <stack> using namespace std; //#define forseach(i,j,n) for(int i=j;i<n;i++) #define debug freopen("in.txt","r",stdin),freopen("out.txt","w",stdout); #define ios ios::sync_with_stdio(0),cin.tie(0),cout.tie(0); //#define PI acos(-1) //typedef long long ll; const int maxn = 5e4+10; int ori[maxn]; bool isori[maxn]; int main() { //debug; ios; stack<char> sk; char ch; //循环输入字符 while(cin>>ch) { //如果为右括号且栈为空 输出NO if(ch==')'&&sk.empty()) { cout<<"NO"; return 0; } //左括号进栈 if(ch=='(') sk.push(ch); //右括号且栈不为空 删除栈顶元素 if(ch==')'&&!sk.empty()) { sk.pop(); } } //如果不为空 说明栈里有左括号 输出NO if(!sk.empty()) { cout<<"NO"; return 0; } //否则为YES cout<<"YES"; return 0; }