第1个回答 2009-07-03
#include"stdio.h"
#include"stdlib.h"
#include"string.h"
#define len sizeof(stack)
#define null 0
typedef struct node
{
char data;
struct node *next;
}stack;
int n;//记录栈中数据的个数;
//初始化栈
stack *initstack()
{
stack *top;
top=null;
return(top);
}
//进栈操作
stack *push(stack *top,char strl[100])
{
stack *p;
int i=0;
p=(stack *)malloc(len);
while(strl[i]!='#')
{
if(i<strlen(strl)/2)
{
p->data=strl[i];
p->next=top;
top=p;
i++;
p=(stack *)malloc(len);
n++;
}
else
break;
}
printf("栈中的数据有%d个\n",n);
return(top);
}
//出栈运算
stack *pop(stack *top,char strl[100])
{
int i=strlen(strl)/2+1;
if(strlen(strl)%2==0)
{
while(top!=null)
{
if(top->data!=strl[i])
printf("这个字符串不是回文!\n");
goto zhou;
top=top->next;
n--;
}
zhou:
if(n!=0)
printf("这个字符串是回文!\n");
}
else
{
while(top!=null)
{
if(top->data!=strl[i])
printf("这个字符串不是回文!\n");
goto cheng;
top=top->next;
n--;
}
cheng:
if(n!=0)
printf("这个字符串是回文!\n");
}
return(top);
}
void main()
{
stack *top;
char strl[100];
top=initstack();
printf("请输入要判断的字符串:!\n");
scanf("%s",&strl);
top=push(top,strl);
top=pop(top,strl);
printf("\n");
}
第2个回答 2009-07-03
#include<stdio.h>
#include<string.h>
#define N 20
int main()
{
char s[N];
int i,len;
scanf("%s",&s);
len=strlen(s);
for(i=0;i<len/2;i++)
{
if(s[i]!=s[len-i-1])
{
printf("No.\n");
break;
}
}
if(i>=len/2)
{
printf("Yes.\n");
}
return 0;
}