使用链表 输入若干个字符数组,然后把数字去掉,再把$改为s,最后判断是否为回文 是的话yes否则no
#include<stdio.h>
#include<ctype.h>
#include<stdlib.h>
#include<string.h>
int i,l;
char chushu(char *a,char *b);
char qian(char *a );
void huiwen(char *a);
int main(void)
{
struct zhifu
{
int no;
char chuan[80];
char chuan2[80];
char huiwen;
struct zhifu *next;
};
struct zhifu *first = NULL;
struct zhifu *ing = NULL;
struct zhifu *ing2=NULL;
struct zhifu *previous = NULL;
char test='\0';
for(;;)
{
printf("\n你想继续输入字符数组吗(Y or N)?);
scanf("%c",&test);
if(tolower(test)=='n')
break;
ing=(struct zhifu*)malloc(sizeof(struct zhifu));
if(first==NULL)
first =ing;
if(previous!=NULL)
previous->next=ing;
printf("\n这是第几次定义字符数组:");
scanf("%d",&ing->no);
printf("\n请定义第%d次字符数组:",ing->no);
scanf("%s",ing->chuan);
getchar();
ing->next=NULL;
previous=ing;
}
for (ing = first; ing != NULL; ing = ing->next) {
printf("%d: %s\n", ing->no, ing->chuan);
}
ing=first;
while(ing!=NULL)
{
char *p = ing->chuan;
char *q = ing->chuan2;
chushu(p,q);
qian(q);
huiwen(q);
ing=ing->next;
}
printf("\nafter modified:\n");
for (ing = first; ing != NULL; ing = ing->next) {
printf("%d: %s\n", ing->no, ing->chuan2);
}
return 0;
}
char chushu(char *a,char *b)
{
for( ; *b = *a; a++)
if( *a <'0' || *a >'9' )
++b;
return(*b);
}
char qian(char *a)
{
for(;*a;a++)
{ if(*a=='$')
*a='s';
i++;
}
return(*a);
}
void huiwen(char *a)
{
printf("%s\n", a);
char *p1 = a;
char *p2 = (a+strlen(a)-1);
while(p1 < p2) {
if(*(p1++) != *(p2--)){
printf("NO\n");
break;
}
else if(p1>=p2)
printf("yes\n");
}
}