Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // Find the largest palindrome made from the product of two 3-digit numbers.
- #include <iostream>
- #include <string>
- #include <cstring>
- #include <boost/lexical_cast.hpp>
- using namespace std;
- string convert_double(double num)
- {
- string str = boost::lexical_cast<string>(num);
- return str;
- }
- bool checkPalindrome(string str)
- {
- int size = str.length();
- for (int i = 0; i < size / 2; i++)
- if (str[i] != str[size - 1 - i])
- return false;
- return true;
- }
- int main()
- {
- double num = 0;
- for (int i = 999; i > 99; i--) {
- for (int j = 999; j > 99; j--) {
- num = i * j;
- if (checkPalindrome(convert_double(num))) {
- cout << num;
- return 0;
- }
- }
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement