室内养什么动物赚钱:我是C语言初学者,请帮我编写函数,判断一个字符串是否是回文。若是回文函数返回值为1,否则返回值为0。

来源:百度文库 编辑:神马品牌网 时间:2024/05/02 13:50:15

楼上的算法没考虑将标点、空格等特殊字符排除在外呀。
#include <string.h>
#include <ctype.h>

/*
To test if a string is a palindrome
return 1 is s is a palindrome
otherwise return 0
*/
int palind(const char *s)
{
int l;
int r;

if (s == NULL) return 0;

l = 0;
r = strlen(s);

while(l<r)
{
while (!isalpha(s[l])) l++;
while (!isalpha(s[r])) r--;
if (tolower(s[l])!=tolower(s[r]))
{
return 0;
}
l++;
r--;
}
return 1;
}

你看这个算法:
int a(char *p)
{
char *Rep;
Rep=strrev(p); /*把串翻转一下*/
return strcmp(p,Rep);
}
不知道你满不满意?

int func(const char* str){
int beg,end;
for(beg=0,end=strlen(str)-1;beg<end;beg++,end--){
if(*(str+beg)!=*(str+end))
break;
}
if(beg<end)
return 0;
else
return 1;
}

你要有真确答案的时候给我 发过来好吗?我也,没有想出来!
谢谢:)