回文判断
回文,英文palindrome,指一个顺着读和反过来读都一样的字符串,比如madam、我爱我,这样的短句在智力性、趣味性和艺术性上都颇有特色,中国历史上还有很多有趣的回文诗。
那么,我们的第一个问题就是:判断一个字串是否是回文?
bool IsPalindrome(const char *s, int n)
{
// 非法输入
if (s == NULL || n < 1)
{
return false;
}
const char* front,*back;
// 初始化头指针和尾指针
front = s;
back = s+ n - 1;
while (front < back)
{
if (*front != *back)
{
return false;
}
++front;
--back;
}
return true;
}