Saleh127

Uva 673

Jun 21st, 2020
158
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.73 KB | None | 0 0
  1. #include <bits/stdc++.h>
  2. using namespace std;
  3. #define ll long long int
  4. #define Faster ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
  5. int main()
  6. {
  7. Faster
  8. ll t;
  9. cin>>t;
  10. cin.ignore();
  11. while (t--)
  12. {
  13. string a;
  14. getline(cin,a);
  15. stack<char>x;
  16. ll l=a.size();
  17. for(ll i=0; i<l; i++)
  18. {
  19. if(x.empty()==0 && x.top()=='(' && a[i]==')')
  20. {
  21. x.pop();
  22. }
  23. else if(x.empty()==0 && x.top()=='[' && a[i]==']')
  24. {
  25. x.pop();
  26. }
  27. else x.push(a[i]);
  28. }
  29. if(x.empty()==1) printf("Yes\n");
  30. else printf("No\n");
  31. }
  32. return 0;
  33. }
Advertisement
Add Comment
Please, Sign In to add comment