Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include<stdio.h>
- #include<string.h>
- int top = -1;
- char stack[100];
- void push (char n)
- {
- stack[++top] = n;
- }
- void pop()
- {
- top--;
- }
- int is_empty()
- {
- if(top == -1) return 1;
- else return 0;
- }
- int main()
- {
- char ch[20];
- int len, i;
- gets(ch);
- len = strlen(ch);
- if(len % 2 != 0)
- {
- printf("Invaild\n");
- return 0;
- }
- else {
- for(i = 0; i < len; i++)
- {
- if(ch[i] == '(' )push(ch[i]);
- else{
- if(is_empty() == 0) pop();
- else {
- printf("Invaild\n");
- return 0;
- }
- }
- }
- if(top == -1) printf("Vaild\n");
- else printf("Invaild\n");
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement