#include
#include
using namespace std;
int main() {
string tar,ss;
cout << “请输入字符串” << endl;
getline(cin, ss);
//int A=65, Z=90, a=97, z=122;
for (int i = 0; i < ss.size(); i++) {
if (ss[i] >= ‘A’ && ss[i] <= ‘Z’)
ss[i] = ss[i] + 32;
}
for (int i = 0,j=0; i < ss.size(); i++) {
if (ss[i] >= ‘a’ && ss[i] <= ‘z’) {
tar+= ss[i];
}
}
int m = tar.size()-1;
if (tar.size() != 0) {
for (int i = 0; i <= (tar.size() / 2 - 1); i++, m–) {
if (tar[i] != tar[m]) {
cout << “非回文字符串” << endl;
break;
}
if (i == (tar.size() / 2 - 1)) {
cout << “是回文字符串。” << endl;
}
}
}
else
cout << “无效” << endl;
return 0;
}
回文plus输入后滤去非字母字符,判断是否为回文
最新推荐文章于 2021-12-08 11:32:01 发布