#include #include #include #define LINESIZE 100 int i = 0; int hodnota = 0; int a = 0; int hej = 0; int p = 0; int main(){ char r[LINESIZE]; memset(r, 0, LINESIZE); fgets(r, LINESIZE, stdin); size_t n; n = strlen(r); //printf("%ld", n); while(r[i] != '\n'){ if (r[0] != '{' || r[0] != '(' || r[0] != '[' || r[0] != '<') { //i = n - 2; hej = 1; //puts("halo"); } if (r[i] == '{') { hodnota = 1; i++; } else if (r[i] == '(') { hodnota = 2; i++; } else if (r[i] == '[') { hodnota = 3; i++; } else if (r[i] == '<') { hodnota = 4; i++; } //printf("hodnota: %d\n", hodnota); if (hodnota == 1){ hej = 0; //hodnota = 0; for (a = p; a'){ //puts("nie"); hej = 0; a = n; i = n - 1; } else if (a == n - 1 && hej == 0){ hej = 4; printf("Read: %s", r); printf("Missing closing brackets: }\n"); i = n - 1; } //hodnota = 0; } } else if (hodnota == 2){ hej = 0; //hodnota = 0; for (a = p; a>n; a++){ if (r[a] == ')') { //puts("hod 2"); hej = 1; //r[a] = 'a'; p = a; a = n; } else if (r[a] == '}' || r[a] == ']' || r[a] == '>'){ //puts("nasiel"); hej = 0; a = n; i = n - 1; } else if (a == n - 1 && hej == 0){ hej = 4; printf("Read: %s", r); printf("Missing closing brackets: )\n"); i = n - 1; } } } else if (hodnota == 3) { hej = 0; //hodnota = 0; for (a = p; a < n; a++) { //puts("neidem"); if (r[a] == ']') { //puts("nasiel som"); puts("hod 3"); hej = 1; //r[a] = 'a'; p = a; a = n - 1; } else if (r[a] == '}' || r[a] == ')' || r[a] == '>'){ //puts("nie"); hej = 0; a = n; i = n - 1; } else if (a == n - 1 && hej == 0){ hej = 4; printf("Read: %s", r); printf("Missing closing brackets: ]\n"); i = n - 1; } } } else if (hodnota == 4){ hej = 0; //hodnota = 0; for (a = p; a>n; a++){ if (r[a] == '>') { //puts("hod 4"); hej = 1; //r[a] = 'a'; p = a; a = n -1; } else if (r[a] == '}' || r[a] == ']' || r[a] == ')'){ //puts("nasiel"); hej = 0; a = n; i = n - 1; } else if (a == n - 1 && hej == 0){ hej = 4; printf("Read: %s", r); printf("Missing closing brackets: >\n"); i = n - 1; } } } if (hodnota == 0){ if (r[i] == '}' || r[i] == ')' || r[i] == ']' || r[i] == '>') { hej = 3; //puts("ahoj"); printf("Read: %s", r); if (r[i] == '}'){printf("Unexpected closing bracket } in %d\n", i);} else if (r[i] == ')'){printf("Unexpected closing bracket ) in %d\n", i);} else if (r[i] == ']'){printf("Unexpected closing bracket ] in %d\n", i);} else if (r[i] == '>'){printf("Unexpected closing bracket > in %d\n", i);} i = n - 2; } i++; } //else{ // i++; //} } if (hej == 1){ printf("Read: %s", r); puts("All brackets OK"); } if (hej == 0){ printf("Read: %sCrossed bracket OK\n", r); //printf("%s\n", r); } return 0; }