#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#define STACK_INIT_SIZE 20
#define STACKINCREMENT
10
#define MAXBUFFER
10
typedef char ElemType;
typedef struct
{
ElemType *base;
ElemType *top;
int stackSize;
}sqStack;
void initStack (sqStack *s)
{
s->base=(ElemType*)malloc(STACK_INIT_SIZE *sizeof(ElemType));
if(!s->base)
{
exit(0);
}
s->top=s->base;
s->stackSize=STACK_INIT_SIZE;
}
void push(sqStack *s,ElemType e)
{
if(s->top-s->base >= s->stackSize)
{
s->base=(ElemType *)realloc(s->base,(s->stackSize+STACKINCREMENT)*sizeof(ElemType));
if(!s->base)
exit(0);
s->top=s->base+s->stackSize;
s->stackSize=s->stackSize+STACKINCREMENT;
}
*(s->top)=e;
s->top++;
}
void pop(sqStack *s,ElemType *e)
{
if(s->base==s->top)
return ;
*e=*--(s->top);
}
int Stacklen(sqStack s)
{
return (s.top-s.base);
}
int stackempty(sqStack *s)
{
if(s->top==s->base)
{
return 0;
}
return 1;
}
int main()
{
sqStack s;
char ch[20];
int i,flag1=0,flag2=0,flag3=0;
ElemType e;
initStack(&s);
scanf("%s",ch);
i=0;
while(ch[i]!='\0')
{
if(ch[i]=='('|| ch[i]=='[' || ch=='{')
push(&s,ch[i]);
if(ch==')' )
{
if( stackempty(&s))
pop(&s,&e);
if(e=='(')
flag1=1;
else
flag1=0;
printf("Extra right brackets");
}
if(ch=='}' )
{
if( stackempty(&s))
pop(&s,&e);
if(e=='{')
flag3=1;
else
flag3=0;
}
if(ch==']' )
{
if( stackempty(&s))
pop(&s,&e);
if(e=='[')
flag2=1;
else
flag2=0;
}
i++;
}
if( stackempty(&s))
{
pop(&s,&e);
if(e=='(')
{
printf("Extra left brackets");
}
}
if(flag1==1 && flag2==1 && flag3==1)
printf("Brackets match");
if(flag1==0 || flag2==0 || flag3==0)
printf("Brackets not match");
return 0;
}