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