Guest User

Untitled

a guest
Mar 24th, 2018
88
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.64 KB | None | 0 0
  1. #include <iostream>
  2. #include <stdio.h>
  3. #include <stack>
  4. #include <string>
  5. using namespace std;
  6. int main() {
  7. int n, i, j;
  8. string str;
  9. stack<int> s;
  10. int count;
  11.  
  12.  
  13. cin >> n;
  14.  
  15. for (i = 0; i < n; i++) {
  16. cin >> str;
  17. count = 0;
  18. for (j = 0; j <= str.size(); j++) {
  19. if (str[j] == '(') {
  20. s.push(str[j]);
  21. count++;
  22. }
  23. else if (str[j] == ')') {
  24. if (s.size() != 0) {
  25. s.pop();
  26. count--;
  27. }
  28. else {
  29. count++;
  30. }
  31. }
  32. }
  33. if (count == 0) {
  34. cout << "YES" << endl;
  35. }
  36. else {
  37. cout << "NO" << endl;
  38. }
  39. for (j = 0; j <= str.size(); j++) {
  40. if (s.size() != 0) {
  41. s.pop();
  42. }
  43. }
  44. }
  45.  
  46. return 0;
  47. }
Add Comment
Please, Sign In to add comment