#include <bits/stdc++.h> #include <stack> using namespace std; int main(){ int t; cin>>t; cin.ignore(); 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.size()>0&&s.top()=='('){ s.pop(); } else{ flag=1; break; } } } if(flag==0&&s.size()==0) cout<<"Yes"<<endl; else cout<<"No"<<endl; } } |
Double click to view unformatted code.