Advertisement
saira12tabassum19

Untitled

Nov 3rd, 2019
128
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.69 KB | None | 0 0
  1.  
  2.  
  3. #include <iostream>
  4. using namespace std;
  5.  
  6. int main()
  7. {
  8.  
  9. int t;
  10. string s; cin>>t; cin.ignore(256,'\n');
  11. while(t--)
  12. {
  13. getline(cin,s);
  14. int count_b=0,count_p=0,count_pr=0,count_br=0;
  15.  
  16. for(int i=0;s[i]!='\0';i++)
  17. {
  18. if(s[i]=='(')count_b++;
  19. if(s[i]==')'){
  20.  
  21. count_br++;
  22. if(count_b>0)
  23. {count_b--;count_br--;}}
  24. if(s[i]=='[')count_p++;
  25. if(s[i]==']'){
  26.  
  27. count_pr++;
  28. if(count_p>0)
  29. {count_p--; count_pr--;}}
  30. }
  31. if(count_b==0&&count_br==0&&count_p==0&&count_pr==0)cout<<"Yes"<<endl;
  32. else cout<<"No"<<endl;
  33. s.clear();
  34. }
  35.  
  36. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement