【编程题】-C++实现:判断字符串在末尾加一个字符,能否构成回文串

来源:互联网 发布:2016网络最新最火的词 编辑:程序博客网 时间:2024/05/22 10:08
///////////////////////////////////////////////////////////////////////////////////////////////////////////  @题目:判断字符串是否回文 //  此题:判断字符串在末尾加一个字符,能否构成回文串。//  @时间 ; 2015.09.19 /////////////////////////////////////////////////////////////////////////////////////////////////////////// 思路:判断arr[1]~arr[n]是否回文即可 #include <iostream>#include <string.h>using namespace std;/* run this program using the console pauser or add your own getch, system("pause") or input loop *///  函数声明bool IsPalindromeStrCore(char* pStr);bool IsPalindromeStr(char* pStr);int main(int argc, char** argv){    char szBuf[] = "coco";    if (IsPalindromeStr(szBuf))    {        printf("YES");    }    else    {        printf("NO");    }    return 0;}///////////////////////////////////////////////////////////////////////////////////////////////////////////  函数实现 bool IsPalindromeStrCore(char* pStr){    int len = strlen(pStr);    for (int i = 0 , j = len - 1 ; i < j ; ++i , --j)    {        if (pStr[i] != pStr[j])            return false;    }       return true;}bool IsPalindromeStr(char* pStr){    if (NULL == pStr || strlen(pStr) > 10 || strlen(pStr) < 2)    {        return false;    }    else    {        return IsPalindromeStrCore(pStr + 1);    }}
0 0
原创粉丝点击