#include<stdio.h>
typedef int Elemtype;
#define MaxSize 100
typedef struct{
char data[MaxSize];
int top;
}SqStack;
void InitStack(SqStack *s)
{
s->top=-1;
}
int Push(SqStack *s,char e)
{
if(s->top==MaxSize-1)
return -1;
s->top++;
s->data[s->top]=e;
return 1;
}
Elemtype Pop(SqStack *s)
{
if(s->top==-1)
return -1;
Elemtype e=s->data[s->top];
s->top--;
return e;
}
int symmetry(char str[])
{
int i,n;
char e;
SqStack st;
InitStack(&st);
for(i=0;str[i]!='\0';i++)
{
Push(&st,str[i]);
}
for(i=0;str[i]!='\0';i++)
{
e=Pop(&st);
if(e!=str[i])
{
printf("不相等!");
break;
}
}
printf("%s",str);
}
int main()
{
char str[MaxSize];
int n;
scanf("%d",&n);
for(int i=0;i<n;i++)
{
scanf("%c",&str[i]);
}
symmetry(str);
}
顺序栈对称串的判断
最新推荐文章于 2024-07-24 10:46:51 发布