andy6804tw
8/2/2016 - 5:09 AM

## http://e-tutor.itsa.org.tw/e-Tutor/mod/programming/view.php?id=24203 這題直接迴圈10000~100000中去找是否整除 再算出另一個數字,最後兩個數字去檢查是否為0~9都有

http://e-tutor.itsa.org.tw/e-Tutor/mod/programming/view.php?id=24203

``````import java.util.*;

public class Main {

public static void main(String[] args) {
Scanner scn = new Scanner(System.in);
int num = scn.nextInt(), num2 = 0, k = 0, count = 0;
for (int i = 10000; i < 100000; i++) {
int tot = 0;
if (i % num == 0) {
num2 = i / num;
char arr1[] = String.valueOf(i).toCharArray(), arr2[] = String.valueOf(num2).toCharArray();
int arr[] = new int[10];
for (int j = 0; j < arr1.length; j++) {
arr[arr1[j] - '0']++;
}
for (int j = 0; j < arr2.length; j++) {
arr[arr2[j] - '0']++;
}
if(arr2.length==4)
arr[0] = 1;
for (k = 0; k < 10; k++) {
if (arr[k] != 1)
break;
}
if (k == 10) {
System.out.printf("%05d / %05d = %d\n", i, num2, num);
count++;
}
}
}
if (count == 0)
System.out.printf("No solutions for %d.\n", num);
}
/*
題目：[C_GD10-易] 整除的數字
作者：1010
時間：西元 2016 年 8 月 */
}``````