Join GitHub today
GitHub is home to over 50 million developers working together to host and review code, manage projects, and build software together.
Sign upGitHub is where the world builds software
Millions of developers and companies build, ship, and maintain their software on GitHub — the largest and most advanced development platform in the world.
【每日一题】- 2019-09-02 - 回文 #158
Comments
|
我这里给出一种“大人的”解法,思路就是从所有可能满足条件的数中暴力搜索即10000 - 99999,每一个数字我都去求它的回文数字, 并且观察每一位是不是否不同,如果都不同,我就用回文数除以原来的数字,得出的数字是整数(确切的说是一位整数)就将其返回。 先说答案, 答案是 21978 * 4 = 87912 为了方便理解,我这里做了两次循环,其实可以放到一起, 大神请忽略~ function reversedNumber(n) {
let r = 0;
while (n >>> 0 !== 0) {
r = r * 10 + (n % 10);
n = (n / 10) >>> 0;
}
return r;
}
function hasDuplicated(n) {
const used = {};
while (n >>> 0 !== 0) {
n = (n / 10) >>> 0;
if (used[n % 10]) return true;
used[n % 10] = true;
}
return false;
}
function t() {
let n = 0;
for (let i = 10000; i < 100000; i++) {
if(hasDuplicated(i)) continue;
n = reversedNumber(i);
if (n / i === (n / i) >>> 0) return `${i} * ${n / i} = ${n}`;
}
}
console.log(t()); // 21978 * 4 = 87912 |
public class Test {
public static void main(String[] args) {
for (int i = 10000; i < 99999; i++) {
int a = i / 10000;
int b = i / 1000 % 10;
int c = i / 100 % 10;
int d = i / 10 % 10;
int e = i % 10;
HashSet<Integer> set = new HashSet<Integer>();
set.add(a);
set.add(b);
set.add(c);
set.add(d);
set.add(e);
if (set.size() == 5) {
for (int j = 1; j < 10; j++) {
if (i * j == (e * 10000 + d * 1000 + c * 100 + b * 10 + a)) {
System.out.println(a + "," + b + "," + c + "," + d + "," + e + "," + j);
}
}
}
}
}
} |
|
? |
? |
|
因为是五个不同的数字,其实循环次数可以再减少一些,就从12345-98765进行搜索
|
|
This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions. |
|
#include<stdio.h> |
|
This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions. |
下面的问题,可以用小学三年级的方法解决,也可以使用初中方程式的方法解决,还可以使用大学的高级编程语言解决。请尝试使用所有方法解决,并进行比较。
有这样一个乘法算式:
这里的每一个字代表一个数字,不同的字代表不同的数字,你能把这些数字都找出来么?