2024-10-26 18:43:36 +00:00
|
|
|
#include <stdio.h>
|
|
|
|
#define MAX 100
|
|
|
|
|
2024-10-26 19:26:38 +00:00
|
|
|
void serch_zatv(char vhod[MAX]) {
|
2024-10-26 19:20:18 +00:00
|
|
|
char first[2] = "{}";
|
|
|
|
char second[2] = "[]";
|
2024-10-26 19:26:38 +00:00
|
|
|
char third[2] = "<>";
|
2024-10-26 19:20:18 +00:00
|
|
|
char fourth[2] = "()";
|
|
|
|
int idx = 0;
|
|
|
|
int idt = 0;
|
2024-10-26 19:26:38 +00:00
|
|
|
char find[50] = {0};
|
2024-10-26 19:20:18 +00:00
|
|
|
|
2024-10-26 19:26:38 +00:00
|
|
|
while (vhod[idx] != '\0') {
|
|
|
|
if (vhod[idx] == first[0]) {
|
|
|
|
find[idt] = first[1];
|
|
|
|
idt++;
|
|
|
|
} else if (vhod[idx] == second[0]) {
|
|
|
|
find[idt] = second[1];
|
|
|
|
idt++;
|
|
|
|
} else if (vhod[idx] == third[0]) {
|
|
|
|
find[idt] = third[1];
|
|
|
|
idt++;
|
|
|
|
} else if (vhod[idx] == fourth[0]) {
|
|
|
|
find[idt] = fourth[1];
|
|
|
|
idt++;
|
|
|
|
} else {
|
|
|
|
for (int i = 0; i < idt; i++) {
|
|
|
|
if (vhod[idx] == find[i]) {
|
|
|
|
find[i] = '.';
|
|
|
|
for (int r = i + 1; r < idt; r++) {
|
|
|
|
if (find[r] != '.' && find[r] != '\0') {
|
|
|
|
printf("Crossed bracket %c at position %d, expected %c\n", vhod[idx], idx, find[i]);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
2024-10-26 19:20:18 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2024-10-26 19:26:38 +00:00
|
|
|
idx++;
|
2024-10-26 19:20:18 +00:00
|
|
|
}
|
2024-10-26 19:26:38 +00:00
|
|
|
|
|
|
|
for (int i = 0; i < idt; i++) {
|
|
|
|
if (find[i] != '.' && find[i] != '\0') {
|
|
|
|
printf("Unmatched bracket\n");
|
|
|
|
return;
|
2024-10-26 19:20:18 +00:00
|
|
|
}
|
|
|
|
}
|
2024-10-26 19:26:38 +00:00
|
|
|
|
|
|
|
printf("All brackets OK\n");
|
2024-10-26 18:43:36 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
int main() {
|
|
|
|
char riadok[MAX];
|
2024-10-26 19:26:38 +00:00
|
|
|
scanf("%s", riadok); // Без амперсанда &
|
2024-10-26 18:43:36 +00:00
|
|
|
|
|
|
|
serch_zatv(riadok);
|
|
|
|
|
|
|
|
return 0;
|
2024-10-26 19:26:38 +00:00
|
|
|
}
|