用栈来写是否回文数,有问题
#include<stdio.h>#include<string.h>
#define maxsize 100
typedef struct {
int a[maxsize];
int top;
}stack;
void init(stack *st)
{
st->top=0;
}
void push(stack *st,int x)
{
if(st->top==maxsize)
{
printf("the stack is full");
}
st->a[st->top]=x;
st->top++;
}
char pop(stack *st)
{
char m;
if(st->top==0)
printf("the stack is empty!");
else
{ st->top=(st->top)-1;
m=st->a[st->top];
}
return m;
}
void main()
{
stack a;
init(&a);
char b[100];
int i,m;
printf("qing shu ru ni xiang shu ru de ge shu:");
scanf("%d",&m);
printf("please input shu :");
for(i=0;i<m;i++)
{
scanf("%c",&b[i]);
push(&a,b[i]);
}
//char n;
for(i=0;i<m;i++)
printf("%c",pop(&a));
printf("\n");
for(i=m-1;i>=0;i--)
{
if(b[i]!=pop(&a))
{ printf("不是回文数!");
break;
}
}
if(i==0)
printf("是回文数!");