分析:只需要枚举fghij就可以算出abcde,然后判断是都所有数字都不相同即可。注意输出格式。
import java.text.DecimalFormat;
import java.util.Scanner;
public class Main{
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
DecimalFormat df = new DecimalFormat("00000");
int T = 0;
while (scanner.hasNext()) {
int N = scanner.nextInt();
if (N == 0) return;
if (T++ > 0) System.out.println();
int count = 0;
int[] used = new int[10];
for (int i = 1234; i < 100000; i++) {
if (judge(i, i * N, used)) {
System.out.println(i * N + " / " + df.format(i) + " = " + N);
count++;
}
}
if (count == 0) System.out.println("There are no solutions for " + N + ".");
}
}
public static boolean judge(int a, int b, int[] used) {
if (b > 98765) return false;
for (int i = 0; i < used.length; i++) used[i] = 0;
if (a < 10000) used[0] = 1;
while (a > 0) {
used[a % 10] = 1;
a /= 10;
}
while (b > 0) {
used[b % 10] = 1;
b /= 10;
}
int sum = 0;
for (int i = 0; i < 10; i++) {
sum += used[i];
}
return (sum == 10);
}
}