Largest palindrome product

简介: https://projecteuler.net/problem=4 1、它是回文数 2、存在2个三位数乘积等于它。 1 #include<iostream> 2 #include<cstdio> 3 using namespace std; 4 bool is_ok(int x) 5 { 6 if(x%10!=x/100000 ||

https://projecteuler.net/problem=4

1、它是回文数

2、存在2个三位数乘积等于它。

 1 #include<iostream>
 2 #include<cstdio>
 3 using namespace std;
 4 bool is_ok(int x)
 5 {
 6     if(x%10!=x/100000 || (x/10)%10!=(x/10000)%10 || (x/100)%10!=(x/1000)%10)
 7         return false;
 8     return true;
 9 }
10 bool is_ok1(int x)
11 {
12     for(int i=100;i<1000;i++)
13         for(int j=100;j<1000;j++)
14         if(i*j==x)
15         {
16     //    cout<<i<<"  "<<j<<endl;
17         return true;
18         }
19     return false;
20 }
21 int main()
22 {
23     for(int i=999999;i>=100000;i--)
24         if(is_ok(i) && is_ok1(i))
25         {
26              cout<<i<<endl;
27              break;
28         }
29     return 0;
30 }
View Code

 

目录
相关文章
|
索引
LeetCode 373. Find K Pairs with Smallest Sums
给定两个以升序排列的整形数组 nums1 和 nums2, 以及一个整数 k。 定义一对值 (u,v),其中第一个元素来自 nums1,第二个元素来自 nums2。 找到和最小的 k 对数字 (u1,v1), (u2,v2) ... (uk,vk)。
167 0
LeetCode 373. Find K Pairs with Smallest Sums
LeetCode 152. Maximum Product Subarray
给定一个整数数组 nums ,找出一个序列中乘积最大的连续子序列(该序列至少包含一个数)。
58 0
LeetCode 152. Maximum Product Subarray
|
人工智能
Constant Palindrome Sum
Constant Palindrome Sum
1048. Find Coins (25)
#include #include #include #include using namespace std; map ma; int main(){ int n, m, t; cin >> n ...
886 0
[LeetCode]--17. Letter Combinations of a Phone Number
Given a digit string, return all possible letter combinations that the number could represent. A mapping of digit to letters (just like on the telephone buttons) is given below. Input:D
1331 0
[LeetCode]--409. Longest Palindrome
Given a string which consists of lowercase or uppercase letters, find the length of the longest palindromes that can be built with those letters. This is case sensitive, for example “Aa” i
1158 0
[LeetCode]--234. Palindrome Linked List
Given a singly linked list, determine if it is a palindrome. Follow up: Could you do it in O(n) time and O(1) space? 我的思路很简单,先遍历一遍找到长度,然后用堆保存着前面一半的数据然后与后面的对比,不一样就false。 /** * Definitio
1234 0
|
canal
[LeetCode]--125. Valid Palindrome
Given a string, determine if it is a palindrome, considering only alphanumeric characters and ignoring cases. For example, “A man, a plan, a canal: Panama” is a palindrome. “race a car”
1083 0

热门文章

最新文章