Problem 4
来源:互联网 发布:网络教学工具 编辑:程序博客网 时间:2024/05/06 19:07
Problem
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.
Code
#include <iostream>using namespace std;int xx(int x){ int result = 1; for (int i = 1; i <= x; i++) { result *= 10; } return result;}int countPlace(int num){ for (int i = 7; i != 0; i--) { int place = xx(i); if (num/xx(i) >= 1) { return i + 1; } }}bool isPalindromicNumber(int num){ int count = countPlace(num); int midnum = count/2; if (count%2 == 0) { for (int i = 0; i != midnum; i++) { int a = num/xx(midnum+i)%10; int b = num/xx(midnum-i-1)%10; if (a != b) { return false; } } } else { for (int i = 1; i <= midnum; i++) { int a = num/xx(midnum+i)%10; int b = num/xx(midnum-i)%10; if (a != b) { return false; } } } return true;}int main(){ int max = 0; int x; int y; for (int i = 999; i != 99; i--) { for (int j = 999; j != 99; j--) { if (isPalindromicNumber(i*j)) { int result = i * j; if (result > max) { max = result; x = i; y = j; } } } } cout << max << endl; cout << "x:" << x << ",y:" << y << endl;}
- Problem 4
- Problem 4
- Problem 4 的困惑
- Project Euler - Problem 4
- Project Euler problem 4
- 4Sum Problem
- 4clojure problem 132
- USACO 1.1 Problem 4
- Project Euler Problem 4
- resin 4 start problem
- Project Euler Problem 4
- problem
- Problem
- problem
- Problem
- Problem
- Problem
- Problem
- problem 1
- 杭电ACM 1096(A+B for Input-Output Practice (VIII))
- Problem 2
- Problem 3
- 置换群的快速幂
- Problem 4
- Winform使用多线程loading画面
- Problem 5
- 在air上打包alternativa3d的桌面项目,附图
- Problem 6
- Windows编程革命简史(转载)
- java内存分布
- Ubuntu下PHP开发环境LAMP搭建
- ebp