#include #include #include using std::string; static string reverse(const string &s) { string result; for(int i = s.size() - 1; i >= 0; i --) result += s[i]; return(result); } static bool isDualPalindrome(int value) { // Turn 'value' into a string std::ostringstream out; out << value; string s = out.str(); // If the length of 's' is an odd number, we're done as // there's no way 's' can become two same-sized palindromes if(s.size() % 2 != 0) return(false); // Extract the two halves and see if they are palindromes string first = s.substr(0, s.size() / 2); string second = s.substr(s.size() / 2); if(first != reverse(first)) return(false); if(second != reverse(second)) return(false); return(true); } int main() { for(int i = 0; i < 1000000; i ++) { if(isDualPalindrome(i)) { std::ostringstream out; out << i; string s = out.str(); string first = s.substr(0, s.size() / 2); string second = s.substr(s.size() / 2); std::cout << "[" << i << "] => [" << first << "] + [" << second << "]\n"; } } return(0); }