Advertisement
Guest User

Untitled

a guest
Feb 21st, 2019
70
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.77 KB | None | 0 0
  1. #include <bits/stdc++.h>
  2.  
  3. using namespace std;
  4.  
  5. main()
  6. {
  7. #ifdef _DEBUG
  8. //freopen("in.txt", "rt", stdin);
  9. #endif // _DEBUG
  10.  
  11. ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
  12.  
  13. string s;
  14. getline(cin, s);
  15.  
  16. int t = 0;
  17. for (int i = 0; i < (int)s.size(); i++)
  18. {
  19. int pw;
  20.  
  21. if (((int)s.size() - i) == 3)
  22. pw = 100;
  23. else if (((int)s.size() - i) == 2)
  24. pw = 10;
  25. else
  26. pw = 1;
  27.  
  28. t += (int(s[i] - '0')) * pw;
  29. }
  30.  
  31. for (int i = 0; i < t; i++)
  32. {
  33. getline(cin, s);
  34.  
  35. stack<char> st;
  36.  
  37. for (auto a : s)
  38. {
  39. if (st.empty() || st.top() != a)
  40. st.push(a);
  41. else
  42. st.pop();
  43. }
  44.  
  45. if (!st.empty())
  46. printf("NO\n");
  47. else
  48. printf("YES\n");
  49. }
  50. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement