#include<iostream> #include<stack> #include<string> using namespace std; int main(){ int T; cin>>T; while(T--){ string str; bool flag=true; cin>>str; stack<char>s; for(int i=0;i<str.size();i++){ if(str[i]=='('){ s.push(str[i]); } else{ if(!s.empty()){ s.pop(); } else{ s.push(str[i]); flag=false; break; } } } if(!s.empty()){ flag=false; } else{ flag=true; } if(flag){ cout<<"Yes"<<endl; } else{ cout<<"No"<<endl; } } } |
Double click to view unformatted code.