Update a1/program.c

This commit is contained in:
Viktor Daniv 2024-10-26 19:26:38 +00:00
parent bc29403958
commit 5cefc98d82

View File

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