Largest palindrome product

problem 4:Largest palindrome product

题意:求由三位数和三位数之积构成的最大回文数字

代码如下:

 1 #ifndef PRO4_H_INCLUDED
 2 #define PRO4_H_INCLUDED
 3
 4 namespace pro4{
 5     bool ispalindromic(int n){
 6         int a[6],k=0;
 7         while(n){
 8             a[k++]=n%10;
 9             n/=10;
10         }
11         for(int i=0;i<k/2;++i)
12             if(a[i]!=a[k-1-i])return 0;
13         return 1;
14     }
15     int solve(){
16         int maxn=0;
17         for(int i=100;i<=999;++i){
18             for(int j=100;j<=999;++j){
19                 int t=i*j;
20                 if(ispalindromic(t)&&t>maxn)maxn=t;
21             }
22         }
23         return maxn;
24     }
25 }
26
27 #endif // PRO4_H_INCLUDED
时间: 2024-08-10 16:36:59

Largest palindrome product的相关文章

PE 4 Largest palindrome product(最大回文)

题目 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. https://projecteuler.net/problem=1 分析 题

【easy】479. Largest Palindrome Product

Find the largest palindrome made from the product of two n-digit numbers Since the result could be very large, you should return the largest palindrome mod 1337. Example: Input: 2 Output: 987 Explanation: 99 x 91 = 9009, 9009 % 1337 = 987 Note:The ra

479. Largest Palindrome Product

问题描述: Find the largest palindrome made from the product of two n-digit numbers. Since the result could be very large, you should return the largest palindrome mod 1337. Example: Input: 2 Output: 987 Explanation: 99 x 91 = 9009, 9009 % 1337 = 987 Note

LeetCode 479 - Largest Palindrome Product - Hard ( Python)

Find the largest palindrome made from the product of two n-digit numbers. Since the result could be very large, you should return the largest palindrome mod 1337. Example: Input: 2 Output: 987 Explanation: 99 x 91 = 9009, 9009 % 1337 = 987 Note: The

projecteuler----&gt;problem=4----Largest palindrome product

title: Largest palindrome product Problem 4 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.

PE 001~010

题意: 001(Multiples of 3 and 5):对小于1000的被3或5整除的数字求和. 002(Even Fibonacci numbers):斐波那契数列中小于等于4 000 000的偶数求和. 003(Largest prime factor):求600 851 475 143的最大质因数. 004(Largest palindrome product):求由两个三位数相乘得到的最大回文数. 005(Smallest multiple):求能被1~20中所有数整除的最小正整数.

欧拉项目004:寻找最大的回文数

Problem 4: Largest palindrome product 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. 寻找有两

Project-Euler problem 1-50

最近闲的做了下Project Euler 上的题目,前面50题都比较简单,简单总结下.代码一般是Python和C/C++的 用Python 做这些题目简直是酸爽啊 一下代码可能不一定是我的,因为不知道论坛里面的回复不是永久的,所以我的代码有的丢了,可能找个和我的意思相近的代码.题目翻译是从 欧拉计划 | Project Euler 中文翻译站上面Copy 的表告我. Problem 1  Multiples of 3 and 5 10以下的自然数中,属于3和5的倍数的有3,5,6和9,它们之和是

欧拉计划(python) problem 4

Largest palindrome product Problem 4 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. pytho