Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- using namespace std;
- int main()
- {
- int t;
- string s; cin>>t; cin.ignore(256,'\n');
- while(t--)
- {
- getline(cin,s);
- int count_b=0,count_p=0,count_pr=0,count_br=0;
- for(int i=0;s[i]!='\0';i++)
- {
- if(s[i]=='(')count_b++;
- if(s[i]==')'){
- count_br++;
- if(count_b>0)
- {count_b--;count_br--;}}
- if(s[i]=='[')count_p++;
- if(s[i]==']'){
- count_pr++;
- if(count_p>0)
- {count_p--; count_pr--;}}
- }
- if(count_b==0&&count_br==0&&count_p==0&&count_pr==0)cout<<"Yes"<<endl;
- else cout<<"No"<<endl;
- s.clear();
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement