1.pallinfrom就是两个前后相同的字符像:otto,anna2.你不能使用任何内置库(除了sdtio.h),所有函数都要自己编写 3.你不需要区分大小写。
#define MAX 500
include <stdio.h>
int getLength(char * word) {
}
void s reversed (char*original,char*copyWord){
}
int checkPallindrom (char*word){
}
int main()
{
char word [MAX];
return 0;
}
这个程序能自动检测出来是否符合pallinfrom这个条件
#define MAX 500
#include <stdio.h>
int getLength(char * word) {
int i = 0; int count = 0;
for (i = 0;; i++)
{
if (*(word + i) != '\0')
count++;
else
break;
}
return count;
}
int checkPallindrom(char*word,int len) {
if (*word == *(word + len - 1))
return 1;
else
return 0;
}
int main()
{
char word[MAX] = {0};
scanf("%s", word);
int len = getLength(word);
int ret = checkPallindrom(word,len);
if (ret)
printf("是Pallindrom类型");
else
printf("不是Pallindrom类型");
return 0;
}
希望对你有用
解答如下
#define MAX 500
#include <stdio.h>
int getLength(char * word)
{
int count;
for(count=0; word[count]!='\0'; count++)
{}
return count;
}
void reversed (char *original,char *copyWord)
{
int j,len=getLength(original);
for(j=0; j<len; j++)
{
copyWord[j]=original[len-1-j];
}
}
int checkPallindrom (char*word)
{
int j,len=getLength(word);
for(j=0; j<len/2; j++)
{
if(word[j]!=word[len-1-j]&&word[j]!=word[len-1-j]+32&&word[j]!=word[len-1-j]-32)
{
return 0;
}
}
return 1;
}
int main()
{
char word [MAX];
gets(word);
if(checkPallindrom(word))
{
printf("符合pallinfrom\n");
}
else
{
printf("不符合pallinfrom\n");
}
return 0;
}