posts - 137,comments - 0,views - 40444
复制代码
//判断字符串是否是回文字符串(考虑大小写,空格和标点符号)
bool palindrome1(string& str) {
  string ret;
  for (auto& c : str) {
    if (isalpha(c)) {
      if (isupper(c)) {
        ret.push_back(tolower(c));
      }
      else {
        ret.push_back(c);
      }
    }
  }
  string target(ret.rbegin(), ret.rend());//翻转字符串
  return target == ret;
}
#include <iostream>
#include <string>
using namespace std;
int main() {
  string str;
  cout << "请输入一串字符(按'q'结束):";
  while (getline(cin, str) && str != "q") {
    if (palindrome1(str)) {
      cout << "该字符串是回文字符串!\n";
    }
    else {
      cout << "该字符串不是回文字符串!\n";
    }
  }
  return 0;
}
复制代码

posted on   wshidaboss  阅读(446)  评论(0编辑  收藏  举报
相关博文:
阅读排行:
· 微软正式发布.NET 10 Preview 1:开启下一代开发框架新篇章
· 没有源码,如何修改代码逻辑?
· PowerShell开发游戏 · 打蜜蜂
· 在鹅厂做java开发是什么体验
· WPF到Web的无缝过渡:英雄联盟客户端的OpenSilver迁移实战
< 2025年2月 >
26 27 28 29 30 31 1
2 3 4 5 6 7 8
9 10 11 12 13 14 15
16 17 18 19 20 21 22
23 24 25 26 27 28 1
2 3 4 5 6 7 8

点击右上角即可分享
微信分享提示