Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #define _CRT_SECURE_NO_WARNINGS
- #include <stdio.h>
- void push(char stack[], char c, int *top_index) {
- *top_index = *top_index + 1;
- stack[*top_index] = c;
- }
- char pop(char stack[], int *top_index) {
- *top_index = *top_index - 1;
- return stack[*top_index + 1];
- }
- int main() {
- int stack_top_index = -1;
- char stack[10];
- char c;
- int ok = 1;
- printf("%d\n", 1 % 2);
- while ((c = getchar()) != '\n') {
- if (c == '(' || c == '[' || c == '{') {
- push(stack, c, &stack_top_index);
- }
- else if (c == ')') {
- if (pop(stack, &stack_top_index) != '(') {
- ok--;
- break;
- }
- }
- else if (c == ']') {
- if (pop(stack, &stack_top_index) != '[') {
- ok--;
- break;
- }
- }
- else if (c == '}') {
- if (pop(stack, &stack_top_index) != '{') {
- ok--;
- break;
- }
- }
- }
- if (ok)
- printf("OK\n");
- else
- printf("NOT OK\n");
- system("pause");
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement