PE - 004

Posted by WildCow on November 13, 2018

题面


A palindromic number reads the same both ways. The largest palindrome made from the product of two 2-digit numbers is 9009 = 91 × 99.

Find the largest palindrome made from the product of two 3-digit numbers.





解决


两个 for 循环直接艹过去= =


#include <bits/stdc++.h>
using namespace std;

bool Chekc(int x)
{
​	string str1;
​	string str2;
​	int t;
​	int li;

	t = x;
	while(t){
		str1 += t % 10;
		t /= 10;
	}
	while(x){
		str2 += x % 10;
		x /= 10;
	}
	reverse(str1.begin(), str1.end());
	li = str1.size();
	for(int i = 0; i < li; i ++){
		if(str1[i] != str2[i]){
			return false;
		}
	}
	
	return true;
}

int main(int argc, char const *argv[])
{
​    int ans;

    ans = -1;
    for(int i = 999; i >= 100; i --){
    	for(int j = i; j >= 100; j --){
    		if(Chekc(i * j)){
    			ans = max(ans, i * j);
    		}
    	}
    }
    printf("%d\n", ans);
    
    return 0;
}