#include<stdio.h>
#include<stdlib.h>
#define SIZE 10
struct brack
{
char*base;
char*top;
int stacksize;
};
void init(struct brack *m);
void push(struct brack *m,char c);
int pop(struct brack *m,char *e);
void main()
{
char ch,t;
int flag;
struct brack sq;
init(&sq);
while((ch=getchar())!='\n')
{
if(ch=='('||ch=='['||ch=='{')
push(&sq,ch);
else if(ch==')'||ch==']'||ch=='}')
{
flag=pop(&sq,&t);
if(flag==0)
break;
else if((ch==')')&&(t=='('))
flag=1;
else if((ch==']')&&(t=='['))
flag=1;
else if((ch=='}')&&(t=='{'))
flag=1;
else {
flag=0;
break;
}
}
}
if(flag==1)
printf("match!!!\n");
else
printf("not match!!!\n");
}
void init(struct brack *m)
{
m->base=m->top=(char *)malloc(SIZE*sizeof(char));
//就是这一行: : cannot convert from 'struct brack *' to 'char *'
if(!m->base)
{printf("cant creat!\n");
exit(0);
}
m->top=m->base;
m->stacksize=SIZE;
}
void push(struct brack *m,char c)
{
if((m->top-m->base)==m->stacksize)
printf("stack full\n");
else
*(m->top++)=c;
}
int pop(struct brack *m,char *e)
{
int FLAG;
if(m->top==m->base)
FLAG=0;
else{
*e=*(--m->top);
FLAG=1;
}
return FLAG;
}