fork download
  1. #include<iostream>
  2. #include<algorithm>
  3. using namespace std;
  4.  
  5. int main() {
  6. ios_base::sync_with_stdio(0);
  7. cin.tie(0);
  8. cout.tie(0);
  9.  
  10. int n, i, j;
  11. int open = 0, close = 0, chk = 0;
  12. cin >> n;
  13. for (i = 0; i < n; i++) {
  14. string arr;
  15. cin >> arr;
  16. j = 0, open = 0, close = 0;
  17. int size = arr.length();
  18. for(j = 0; j < size; j++) {
  19. if (arr[j] == '(')
  20. open++;
  21. else if (arr[j] == ')') {
  22. close++;
  23. if (close > open) {
  24. cout << "NO\n";
  25. chk++;
  26. break;
  27. }
  28. }
  29. }
  30. if (open == close) {
  31. cout << "YES\n";
  32. }
  33. else {
  34. if (chk) break;
  35. cout << "NO\n";
  36. }
  37. }
  38.  
  39. return 0;
  40. }
Success #stdin #stdout 0s 4388KB
stdin
6
(())())
(((()())()
(()())((()))
((()()(()))(((())))()
()()()()(()()())()
(()((())()(
stdout
NO