Update a1/program.c
This commit is contained in:
parent
ba66ca38db
commit
c3c2e52c68
12
a1/program.c
12
a1/program.c
@ -35,13 +35,13 @@ void check_brackets(const char *code) {
|
|||||||
// Якщо закрита дужка
|
// Якщо закрита дужка
|
||||||
else if (c == ')' || c == '}' || c == ']' || c == '>') {
|
else if (c == ')' || c == '}' || c == ']' || c == '>') {
|
||||||
if (stack_top < 0) {
|
if (stack_top < 0) {
|
||||||
printf("Unexpected closing bracket %c in %d\n", c, i);
|
printf("Unexpected closing bracket %c at position %d\n", c, i);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
char top = stack[stack_top--];
|
char top = stack[stack_top--];
|
||||||
char expected = expected_close(top);
|
char expected = expected_close(top);
|
||||||
if (expected != c) {
|
if (expected != c) {
|
||||||
printf("Crossed bracket %c in %d, expected %c\n", c, i, expected);
|
printf("Crossed bracket %c at position %d, expected %c\n", c, i, expected);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -49,7 +49,11 @@ void check_brackets(const char *code) {
|
|||||||
|
|
||||||
// Перевірка, чи всі дужки закриті
|
// Перевірка, чи всі дужки закриті
|
||||||
if (stack_top >= 0) {
|
if (stack_top >= 0) {
|
||||||
printf("Missing closing brackets: %c\n", expected_close(stack[stack_top]));
|
printf("Missing closing brackets: ");
|
||||||
|
while (stack_top >= 0) {
|
||||||
|
printf("%c", expected_close(stack[stack_top--]));
|
||||||
|
}
|
||||||
|
printf("\n");
|
||||||
} else {
|
} else {
|
||||||
printf("All brackets OK\n");
|
printf("All brackets OK\n");
|
||||||
}
|
}
|
||||||
@ -67,4 +71,4 @@ int main() {
|
|||||||
check_brackets(code);
|
check_brackets(code);
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
Loading…
Reference in New Issue
Block a user