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

IDE:codeblocks

日期:2019/12/3

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

#include <iostream>
#include <cstring>
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;
}

发布了57 篇原创文章 · 获赞 2 · 访问量 1860

猜你喜欢

转载自blog.csdn.net/weixin_43476969/article/details/103368849