- 判断是否构成回文
答案
- 2023-7-25 16:00:18 @
#include <iostream>
#include <string>
#include <algorithm>
bool isPalindrome(const std::string& str) {
std::string reversedStr = str;
std::reverse(reversedStr.begin(), reversedStr.end());
return str == reversedStr;
}
int main() {
std::string input;
std::getline(std::cin, input); // 读取一行输入
// 移除输入末尾的 '.' 字符
input = input.substr(0, input.length() - 1);
// 判断输入字符串是否构成回文
if (isPalindrome(input)) {
std::cout << "TRUE" << std::endl;
} else {
std::cout << "FALSE" << std::endl;
}
return 0;
}
0 条评论
目前还没有评论...
信息
- ID
- 286
- 时间
- 1000ms
- 内存
- 256MiB
- 难度
- 4
- 标签
- 递交数
- 47
- 已通过
- 18
- 上传者