#include <bits/stdc++.h> #include <stack> using namespace std; int main(){ int t; cin>>t; getchar(); while(t--){ string str; getline(cin,str); stack<char> s; int flag=0; for(int i=0;i<str.size();i++){ if(str[i]=='('){ s.push(str[i]); } else if(str[i]==')'){ if(!s.empty()){ s.pop(); } else{ flag=1; break; } } } if(flag==0) cout<<"Yes"<<endl; else cout<<"No"<<endl; } } |
Double click to view unformatted code.