第1个回答 2006-05-18
楼上的算法没考虑将标点、空格等特殊字符排除在外呀。
#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;
}本回答被提问者采纳
第2个回答 2006-05-18
你看这个算法:
int a(char *p)
{
char *Rep;
Rep=strrev(p); /*把串翻转一下*/
return strcmp(p,Rep);
}
不知道你满不满意?
第3个回答 2012-12-02
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;
}
第4个回答 2006-05-18
你要有真确答案的时候给我 发过来好吗?我也,没有想出来!
谢谢:)