*** checkRevStr.cpp 查看字符串是否是回文

#include <iostream>
#include <string.h>
using namespace std;
bool checkRevStr (const char * src)
{
    if (src == NULL) return false;
    const char * end = src + strlen(src) - 1;
    while (*src++ == *end--);
    return (src<end)?(false):(true);
}
int main()
{
    char a[] = "level";
    char b[] = "hanna";
    if (checkRevStr(b))
    {
        cout << "yes, it is!" << endl;
    }
    else
    {
        cout << "No, it is not!" << endl;
    }
    return 0;
}

 

posted @ 2018-12-23 19:18  super行者  阅读(149)  评论(0编辑  收藏  举报