diff --git a/a1/program.c b/a1/program.c index bfb66f7..8792eba 100644 --- a/a1/program.c +++ b/a1/program.c @@ -2,7 +2,58 @@ #define MAX 100 void serch_zatv(char vhod[MAX]){ - printf("%s", vhod); + + char first[2] = "{}"; + char second[2] = "[]"; + char thrid[2] = "<>"; + char fourth[2] = "()"; + int idx = 0; + int idt = 0; + char find[50]; + + while(vhod[idx] != "\0"){ + + if(vhod[idx] == first[0]){ + find[idt] = first[1]; + idt++; + } + + if(vhod[idx] == second[0]){ + find[idt] = second[1]; + idt++; + } + + if(vhod[idx] == thrid[0]){ + find[idt] = thrid[1]; + idt++; + } + + if(vhod[idx] == fourth[0]){ + find[idt] = fourth[1]; + idt++; + } + + for(int i = 0; i < idt; i++){ + if(vhod[idx] = find[i]){ + 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++; + } + for(int i = 0; i < idt){ + if(find[i] != "." || find[i] != "\0"){ + printf("herna); + return 0; + } + } + printf("All brackets OK"); }