Advertisement
shohan11421

check

Mar 24th, 2018
106
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.77 KB | None | 0 0
  1. #include<stdio.h>
  2. #include<string.h>
  3. int top = -1;
  4. char stack[100];
  5. void push (char n)
  6. {
  7.     stack[++top] = n;
  8. }
  9. void pop()
  10. {
  11.     top--;
  12. }
  13. int is_empty()
  14. {
  15.     if(top == -1) return 1;
  16.     else return 0;
  17. }
  18. int main()
  19. {
  20.     char ch[20];
  21.     int len, i;
  22.     gets(ch);
  23.     len = strlen(ch);
  24.     if(len % 2 != 0)
  25.     {
  26.         printf("Invaild\n");
  27.         return 0;
  28.     }
  29.     else {
  30.         for(i = 0; i < len; i++)
  31.         {
  32.             if(ch[i] == '(' )push(ch[i]);
  33.             else{
  34.                 if(is_empty() == 0) pop();
  35.                 else {
  36.                     printf("Invaild\n");
  37.                     return 0;
  38.                 }
  39.             }
  40.         }
  41.         if(top == -1) printf("Vaild\n");
  42.         else printf("Invaild\n");
  43.     }
  44. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement