//判断字符串是否是回文字符串(考虑大小写,空格和标点符号)
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 2024-02-20 18:37  wshidaboss  阅读(408)  评论(0编辑  收藏  举报