输入一串字符,字符个数不超过100,且以"."结束。判断它们是否构成回文。 输入描述 输入只有一行,包括一串字符. 输出描述 输出只有一行.TRUE 或者FALSE(c++代码)
时间: 2024-04-16 22:25:43 浏览: 37
好的,下面是使用C++编写的判断字符串是否构成回文的代码示例:
```cpp
#include <iostream>
#include <string>
#include <algorithm>
using namespace std;
bool isPalindrome(string str) {
string reversedStr = str;
reverse(reversedStr.begin(), reversedStr.end()); // 反转字符串
return str == reversedStr; // 判断反转后的字符串是否与原字符串相等
}
int main() {
string input;
getline(cin, input);
input = input.substr(0, input.size() - 1); // 去除字符串末尾的"."
if (isPalindrome(input)) {
cout << "TRUE" << endl;
} else {
cout << "FALSE" << endl;
}
return 0;
}
```
这段代码会读取一行输入,然后判断输入的字符串是否构成回文。最后输出TRUE或FALSE。请确保你的C++编译器支持C++11标准或更高版本。如果你有其他要求或需要更复杂的处理逻辑,请告诉我。
相关推荐
![cpp](https://img-home.csdnimg.cn/images/20210720083646.png)
![txt](https://img-home.csdnimg.cn/images/20210720083642.png)
![](https://img-home.csdnimg.cn/images/20210720083646.png)
![rar](https://img-home.csdnimg.cn/images/20210720083606.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![pas](https://img-home.csdnimg.cn/images/20210720083646.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![docx](https://img-home.csdnimg.cn/images/20210720083331.png)