Advertisement
Guest User

zatvorky

a guest
Oct 23rd, 2016
168
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.91 KB | None | 0 0
  1. #define _CRT_SECURE_NO_WARNINGS
  2. #include <stdio.h>
  3.  
  4. void push(char stack[], char c, int *top_index) {
  5.     *top_index = *top_index + 1;
  6.     stack[*top_index] = c;
  7. }
  8.  
  9. char pop(char stack[], int *top_index) {
  10.     *top_index = *top_index - 1;
  11.     return stack[*top_index + 1];
  12. }
  13.  
  14.  
  15.  
  16. int main() {
  17.     int stack_top_index = -1;
  18.     char stack[10];
  19.     char c;
  20.     int ok = 1;
  21.  
  22.     printf("%d\n", 1 % 2);
  23.  
  24.     while ((c = getchar()) != '\n') {
  25.         if (c == '(' || c == '[' || c == '{') {
  26.             push(stack, c, &stack_top_index);
  27.         }
  28.         else if (c == ')') {
  29.             if (pop(stack, &stack_top_index) != '(') {
  30.                 ok--;
  31.                 break;
  32.             }
  33.         }
  34.         else if (c == ']') {
  35.             if (pop(stack, &stack_top_index) != '[') {
  36.                 ok--;
  37.                 break;
  38.             }
  39.         }
  40.         else if (c == '}') {
  41.             if (pop(stack, &stack_top_index) != '{') {
  42.                 ok--;
  43.                 break;
  44.             }
  45.         }
  46.     }
  47.  
  48.     if (ok)
  49.         printf("OK\n");
  50.     else
  51.         printf("NOT OK\n");
  52.     system("pause");
  53.     return 0;
  54. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement