#include<iostream>
#include<string>
#include<ctype.h>
using namespace std;
bool huiwen(string s) {
int j = 0;
for (int i = 0, j = s.size() - 1; i < j; i++, j--) {
while (isalnum(s[i]) == false && i < j) i++;
while (isalnum(s[i]) == false && i < j) j--;
if (toupper(s[i]) != toupper(s[j])) {
return false;
}
else {
return true;
}
}
}
int main()
{
string s;
cout << "Please input a string" << endl;
getline(cin, s);
if (huiwen(s) == true) {
cout << "The string is a palindrome" << endl;
}
else{
cout << "The string is not a palindrome" << endl;
}
system("pause");
return 0;
}
第三次上机 第三题
最新推荐文章于 2021-07-22 10:36:40 发布