fork download
  1. #include <iostream>
  2. #include <vector>
  3. using namespace std;
  4.  
  5. int main() {
  6. int countResult = 0;
  7. int firstCheck = 0;
  8. string parentheseString;
  9. cin >> parentheseString;
  10.  
  11.  
  12. int stringLength = parentheseString.size();
  13. vector<int> convertToInt(stringLength);
  14. for (int i = 0; i < stringLength; i++) {
  15. convertToInt[i] = (parentheseString[i] == '('? 1 : -1);
  16. firstCheck += (parentheseString[i] == '('? 1 : -1);
  17. }
  18. if ((firstCheck == 2) || (firstCheck == -2)) {
  19. for (int i = 0; i < stringLength; i++) {
  20. int checkSum = 0;
  21. convertToInt[i] = (convertToInt[i] == 1)? (convertToInt[i] = -1) : (convertToInt[i] = 1);
  22. for (int j = 0; j < stringLength; j++) {
  23. checkSum += convertToInt[j];
  24. if(checkSum < 0) {
  25. break;
  26. }
  27. }
  28. convertToInt[i] = (convertToInt[i] == 1)? (convertToInt[i] = -1) : (convertToInt[i] = 1);
  29. if(checkSum == 0) {
  30. countResult++;
  31. }
  32. }
  33. }
  34. cout << countResult;
  35. return 0;
  36. }
Success #stdin #stdout 0.01s 5316KB
stdin
()(())))
stdout
4