Created
July 26, 2012 12:47
-
-
Save rhysd/3181839 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #include <iostream> | |
| #include <string> | |
| bool is_palindrome(int const i) | |
| { | |
| auto s = std::to_string(i); | |
| for(auto f=s.begin(), l=s.end()-1; f<=l; ++f, --l){ | |
| if(*f!=*l) return false; | |
| } | |
| return true; | |
| } | |
| int main() | |
| { | |
| int max_val = 0; | |
| for(int i=100; i<1000; ++i){ | |
| for(int j=i; j<1000; ++j){ | |
| if(is_palindrome(i*j)){ | |
| max_val = std::max(max_val, i*j); | |
| } | |
| } | |
| } | |
| std::cout << max_val << std::endl; | |
| return 0; | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment