C++判断字符串是否是回文

IDE:codeblocks

日期:2019/12/3

功能:编写一个程序,判断字符串是否是回文。所谓回文,是指顺读和倒读都一样的字符串,例如:level,deed,121等都是回文。

#include 
#include 
using namespace std;

bool judgeStr(char []);

int main(void)
{
    char str[20];
    cout<<"输入一个字符串"<<endl;
    cin>>str;
    cout<<judgeStr(str);
    return 0;
}

bool judgeStr(char str[])
{
    int len = strlen(str),i,j;
    for(i=0,j=len-1;i<=len/2;i++,j--)
    {
        if(str[i]!=str[j])
            return 0;
    }
    return 1;
}

你可能感兴趣的:(C++判断字符串是否是回文)