我是靠谱客的博主 粗暴樱桃,这篇文章主要介绍c++判断一个字符串是否是回文字符串,现在分享给大家,希望可以做个参考。

c++判断一个字符串是否是回文字符串

#include<iostream>
#include<string>
using namespace std;
//Wassamassaw
bool isPalindrome(string s,int n) {
    int i = 0, j = n - 1;
    while (i <= j) {
        if (s[i] == s[j] || s[i]-32 == s[j] || s[i] == s[j]-32) {
            i++;
            j--;
        }else{
            return false;
        }
    }
    return true;
}
int main() {
    string s;
    int n;
    bool flag;
    while(cin>>s){
        n = s.length();
        flag = isPalindrome(s, n);
        if (flag) {
            cout << "Bingle! Palindrome." << endl;
        }else{
            cout << "Not Palindrome." << endl;
        }
    }



    return 0;
}

最后

以上就是粗暴樱桃最近收集整理的关于c++判断一个字符串是否是回文字符串的全部内容,更多相关c++判断一个字符串是否是回文字符串内容请搜索靠谱客的其他文章。

本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
点赞(102)

评论列表共有 0 条评论

立即
投稿
返回
顶部