#include <iostream>
#include <vector>
#include<string>
using namespace std;
int main() {
int is_palindrome = 1;
string s;
cout << "请输入一组字符串:" << endl;
cin >> s;
vector<char>v1;
for (int i = 0; i < s.length(); i++) {
if (s[i] >= 'a' && s[i] <= 'z') {
v1.push_back(s[i]);
}
else if (s[i] >= 'A' && s[i] <= 'Z') {
v1.push_back(s[i]+32);
}
}
int const a = v1.size();
for (int n = 0; n < a / 2; n++) {
if (v1.at(n) != (v1.at(a - n - 1)))
{
is_palindrome = 0;
break;
}
}
if (is_palindrome)
cout << "The string is a palindrome" << endl;
else
cout << "The string is not a palindrome" << endl;
return 0;
}
请输入一组字符串:
aS,sa123
The string is a palindrome
C:\Users\86178\source\repos\题3\Debug\题3.exe (进程 7744)已退出,代码为 0。
要在调试停止时自动关闭控制台,请启用“工具”->“选项”->“调试”->“调试停止时自动关闭控制台”。
按任意键关闭此窗口. . .
第二次上机作业第三题,判断回文数
最新推荐文章于 2021-07-22 10:36:39 发布