//Answer on Question #42159 - Programming - C++
#include <algorithm>
#include <iostream>
#include <string>
#include <cctype>
using namespace std;
bool notIsalnum(int c) {
return !::isalnum(c);
}
bool Palindrome(const string& phrase) {
string s = phrase;
s.erase(remove_if(s.begin(), s.end(), notIsalnum), s.end());
transform(s.begin(), s.end(), s.begin(), ::toupper);
return s == string(s.rbegin(), s.rend());
}
int main() {
cout << "Input word or phrase: " << endl;
string phrase;
getline(cin, phrase);
cout << "\"" << phrase << "\" is ";
if (!Palindrome(phrase)) cout << "not ";
cout << "a palindrome" << endl;
}
Comments
Leave a comment