Обновить a1/program.c
This commit is contained in:
parent
90f9268e8c
commit
8ec9471e73
17
a1/program.c
17
a1/program.c
@ -13,9 +13,10 @@ int main() {
|
||||
StackItem stack[MAX_LEN];
|
||||
int top = -1;
|
||||
|
||||
|
||||
fgets(line, sizeof(line), stdin);
|
||||
|
||||
// Odstránime nový riadok na konci vstupu, ak existuje
|
||||
// Odstránenie nového riadku na konci vstupu, ak existuje
|
||||
line[strcspn(line, "\n")] = 0;
|
||||
printf("Read: %s\n", line);
|
||||
|
||||
@ -54,8 +55,20 @@ int main() {
|
||||
}
|
||||
}
|
||||
|
||||
// Ak sú v zásobníku neuzavreté otváracie zátvorky
|
||||
if (top != -1) {
|
||||
printf("Unmatched opening bracket %c at position %d\n", stack[top].bracket, stack[top].position);
|
||||
printf("Missing closing brackets: ");
|
||||
while (top != -1) {
|
||||
char expected;
|
||||
switch (stack[top--].bracket) {
|
||||
case '(': expected = ')'; break;
|
||||
case '{': expected = '}'; break;
|
||||
case '[': expected = ']'; break;
|
||||
case '<': expected = '>'; break;
|
||||
}
|
||||
printf("%c", expected);
|
||||
}
|
||||
printf("\n");
|
||||
} else {
|
||||
printf("All brackets OK\n");
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user