fork(1) download
  1. #include <cstdio>
  2. #include <cstring>
  3.  
  4. bool func(char * str, int kol){
  5. for (int i = 0; i < kol; i++){
  6. if (str[i] == ')'){
  7. for (int j = i - 1; j >= 0; j--){
  8. if (str[j] == '('){
  9. str[i] = str[j] = '*';
  10. break;
  11. func(str, kol);
  12. }
  13. if (str[j] == '{'){
  14. printf("ERROR");
  15. return false;
  16. }
  17. }
  18. }
  19. if (str[i] == '}'){
  20. for (int j = i - 1; j >= 0; j--){
  21. if (str[j] == '{'){
  22. str[i] = str[j] = '*';
  23. break;
  24. func(str, kol);
  25. }
  26. if (str[j] == '('){
  27. printf("ERROR");
  28. return false;
  29. }
  30. }
  31. }
  32. }
  33. }
  34.  
  35. int main(void) {
  36. char test[] = "(";
  37. printf("%s", (func(test, strlen(test))) ? "OK" : "FAIL");
  38. return 0;
  39. }
  40.  
Success #stdin #stdout 0s 3340KB
stdin
Standard input is empty
stdout
OK