Created
August 9, 2015 12:04
-
-
Save cengiz-io/1441b39f3f8a9f31f8a3 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 <sstream> | |
| using namespace std; | |
| bool isPalindrome(int n) { | |
| int reversedN = 0; | |
| stringstream originalStr; | |
| originalStr << n; | |
| stringstream reversedStr; | |
| reversedStr << string(originalStr.str().rbegin(), originalStr.str().rend()); | |
| reversedStr >> reversedN; | |
| return n == reversedN; | |
| } | |
| int main() { | |
| int largestPalindrome = 0; | |
| for (int x = 800; x < 1000; x++) { | |
| for (int y = 800; y < 1000; y++) { | |
| int product = x * y; | |
| if (isPalindrome(product) && product > largestPalindrome) { | |
| largestPalindrome = product; | |
| } | |
| } | |
| } | |
| cout << largestPalindrome << endl; | |
| return 0; | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment