#include <bits/stdc++.h> using namespace std; int main(){ int t; cin>>t; while(t--){ string kh; stack<char> st; cin>>kh; bool f = true; for(int i = 0; i<kh.size(); i++){ if(kh[i]=='('){ st.push(kh[i]); } else{ if(!st.empty()){ if(st.top()=='('){ st.pop(); } else{ f = false; } } else{ f=false; } } } if(!st.empty()){ f = false; } if(f){ cout<<"Yes"<<endl; } else{ cout<<"No"<<endl; } } return 0; } |
Double click to view unformatted code.