~cpp #include <iostream> using namespace std; bool isPalindrome(char *string, int len) { bool isPal = false; for(int i = 0; i < len/2; i++) { if(string[i] == string[len-i-1]) isPal = true; else { isPal = false; break; } } return isPal; } int main() { char str[20]; int len; while(cin >> str) { len = strlen(str); if(isPalindrome(str, len)) cout << "->true" << endl; else cout << "->false" << endl; } return 0; }
~cpp #include <iostream> using namespace std; bool isPalindrome(char *string, int len) { bool isPal = false; if(string[0] >= 'a' && string[0] <= 'z' || string[0] >= 'A' && string[0] <= 'Z') { for(int i = 0; i < len/2; i++) { if(string[i] == string[len-i-1]) isPal = true; else { isPal = false; break; } } } else { for(int i = 0; i < (len-1)/2; i += 2) { for(int j = 0; j < 2; j++) { if(string[i+j] == string[len-i-2+j]) isPal = true; else { isPal = false; break; } } } } return isPal; } int main() { char str[20]; int len; while(cin >> str) { len = strlen(str); if(len == 1) cout << "->true" << endl; else if(isPalindrome(str, len)) cout << "->true" << endl; else cout << "->false" << endl; } return 0; }