Advertisement
Guest User

Untitled

a guest
Jun 16th, 2019
63
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.67 KB | None | 0 0
  1. #include <cstdio>
  2. #include <iostream>
  3. #include <stack>
  4. #include <string>
  5. using namespace std;
  6.  
  7. int main(void)
  8. {
  9. int n;
  10. scanf("%d", &n);
  11.  
  12. while(n--) {
  13. string s;
  14. cin >> s;
  15.  
  16. stack<char> stack;
  17. bool isWrong = false;
  18. for(int i = 0;i<s.length();i++) {
  19. if(s[i] == '(') stack.push('(');
  20. else if(s[i] == ')' && !stack.empty()) stack.pop();
  21. else if(s[i] == ')' && stack.empty()) {
  22. puts("NO");
  23. isWrong = true;
  24. break;
  25. }
  26. }
  27. if(isWrong) continue;
  28.  
  29. if(stack.empty()) puts("YES");
  30. else puts("NO");
  31. }
  32.  
  33. return 0;
  34. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement