#include <iostream>
#include <string.h>
using namespace std;
bool isAlphanumeric(char c) {
return ('a' <= c && c <= 'z')
|| ('A' <= c && c <= 'Z')
|| ('0' <= c && c <= '9');
}
bool isPalindrome(string s) {
int i = 0;
int j = s.size() - 1;
while (i < j) {
if (!isAlphanumeric(s[i])) {
++i;
} else if (!isAlphanumeric(s[j])) {
--j;
} else if (s[i] == s[j]
|| s[i] - s[j] == 32
|| s[j] - s[i] == 32 ) {
++i; --j;
} else {
return false;
}
}
return true;
}
int main (int argc, const char * argv[]) {
string s = "A man, a plan, a canal: Panama";
cout << "\"" << s << "\"" << " is " << (isPalindrome(s)? "" : "not ") << "palindrome" << endl;
s = "race a car";
cout << "\"" << s << "\"" << " is " << (isPalindrome(s)? "" : "not ") << "palindrome" << endl;
s = "Step on hose-pipes? Oh no, pets.";
cout << "\"" << s << "\"" << " is " << (isPalindrome(s)? "" : "not ") << "palindrome" << endl;
return 0;
}