int main ()
{
	printf("%d\n",ReverseNumber(5170984));
	printf("%d\n",ReverseNumber(406567));
	printf("%d\n",ReverseNumber(368750));
	printf("%d\n",ReverseNumber(2369510));
	printf("%d\n",ReverseNumber(2183293));
	return 0;
}
예제 #2
0
int main(){

	std::vector<int> palindrome(899);
	auto i = 100;
	std::cout << "Generating list of numbers to multiply..." << std::endl;
	std::generate(palindrome.begin(), palindrome.end(), [&](){return i++; });
	std::vector<int> solutions;
	auto k = 0;

	std::cout << "Checking palindromicity of products..." << std::endl;
	for (int a = 898; a > 0; a--){
		for (int b = 898; b > 0; b--){
			if (ReverseNumber((palindrome[a] * palindrome[b])) == (palindrome[a] * palindrome[b])){
				solutions.push_back(palindrome[a] * palindrome[b]);
			}
		}
	}

	auto trueSolution = 0;
	std::cout << "Determining largest palindromic number..." << std::endl;
	for (int j = 0; j < solutions.size(); j++){
		if (solutions[j] > trueSolution){
			trueSolution = solutions[j];
		}
	}
	std::cout << "The answer is: " << trueSolution << std::endl;

	system("Pause");
	return 0;
}
예제 #3
0
int ReverseNumber(int n, int partial = 0){
	if (n == 0)
		return partial;
	return ReverseNumber(n / 10, partial * 10 + n % 10);
}