#include<stdio.h>
#include<malloc.h>
#include<stdlib.h>
#include<string.h>
typedef struct{
char *base;
char *top;
int stacksize;
}SqStack;
int InitStack(SqStack &S){
S.base = (char *)malloc(100*sizeof(char));
if(!S.base){
printf("储存空间分配失败");
exit(-2);
}
S.top = S.base;
S.stacksize = 100;
return 1;
}
char GetTop(SqStack S){
if(S.top!=S.base)
return *(S.top-1);
}
int Push(SqStack &S,char e){
if(S.top-S.base==S.stacksize){
/**printf("栈满");
S.base = (char *)realloc(S.base,(S.stacksize+10)*sizeof(char));
if(!S.base){
printf("储存空间分配失败");
exit(-2);
}
S.top = S.base;
S.stacksize+=10; */
return 0;
}
*S.top++ = e;
return 1;
}
int Pop(SqStack &S,char &e){
if(S.base!=S.top)
e = *--S.top;
return 1;
}
int main(){
SqStack S,W;
int i=0;
char a[100],x,y;
InitStack(S);
InitStack(W);
printf("请输入表达式,以!为结束标志:");
x = getchar();
while(x!='!') {
Push(S,x);
a[i]=x;
i++;
x=getchar() ;
}
for(int j=0;j<i;j++){
Pop(S,y);
if(a[j]!=y){
printf("不中心对称");
return 0;
}
}
printf("中心对称");
return 0;
}