Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <stdlib.h>
- /* run this program using the console pauser or add your own getch, system("pause") or input loop */
- struct element {
- char sym;
- struct element *p;
- };
- char set[]="{(())}[{(({(())}[][][]()()))}[][][]()({(({(())}[][][]()()))}[][][]()())][][]()()";
- int main(int argc, char *argv[]) {
- struct element *top=NULL,*memory;
- int i=0,j;
- while(set[i]) {
- memory=(struct element*)malloc(sizeof(struct element));
- memory->p=top;
- memory->sym=set[i];
- top=memory;
- if (((top->sym==')')&&((top->p)->sym=='('))||((top->sym==']')&&((top->p)->sym=='['))||((top->sym=='}')&&((top->p)->sym=='{'))) {
- for (j=0;j<2;j++) {
- memory=top->p;
- free(top);
- top=memory;
- }
- }
- i++;
- }
- if (top) printf("Error\n");
- else printf("OK");
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement