#include <stdio.h>
#include <stdlib.h>
struct sta{
char a;
struct sta *next;
};
push(char c, struct sta **pp)
{
struct sta *new;
new = malloc(sizeof(struct sta));
new->a = c;
new->next = *pp;
*pp = new;
}
pop(char c, struct sta **pp)
{
switch(c)
{
case ')':
if((*pp)->a != '(')
printf("error! lost \" %c... \"\n",(*pp)->a);
break;
case ']':
if((*pp)->a != '[')
printf("error! lost \" %c... \"\n",(*pp)->a);
break;
case '}':
if((*pp)->a != '{')
printf("error! lost \" %c... \"\n",(*pp)->a);
break;
}
*pp = (*pp)->next;
}
main()
{
char c;
struct sta *p;
p = malloc(sizeof(struct sta));
p->next = NULL;
while((c = getc(stdin)) != EOF)
{
if(c == '(')
{
push(c, &p);
}
else if(c == ')')
{
pop(c, &p);
}
if(c == '[')
{
push(c, &p);
}
else if(c == ']')
{
pop(c, &p);
}
if(c == '{')
{
push(c, &p);
}
else if(c == '}')
{
pop(c, &p);
}
}
}