English Deutsch Français Italiano Español Português 繁體中文 Bahasa Indonesia Tiếng Việt ภาษาไทย
所有分類

0~9不能重複,填入這算式裡
o o
* o
--------
o o o
- o o
-------
o o

解釋:一個 2 位數乘以一個 1 位數等於一個 3 位數
再減一個 2 位數等於一個 2 位數

拜託各位大大幫忙!! 非常感謝(鞠躬)

2007-03-26 13:54:47 · 2 個解答 · 發問者 玟倩 1 in 電腦與網際網路 程式設計

2 個解答

我用C寫了個程式
得到4組解
06 * 9 = 132 - 78 = 54
07 * 9 = 145 - 82 = 63
09 * 6 = 132 - 78 = 54
09 * 7 = 145 - 82 = 63
由於程式太冗長
故不貼出

關於樓上的Java程式
雖然沒學過Java看不太懂al.xxx的意思
我猜是紀錄哪些數字用過的意思吧(?)
如果是這樣
那我覺得程式應該是錯在
迴圈跑完的時候沒有把它歸0(或是我沒看到?)
所以下次再跑的時候會造成
明明沒用過的數字,程式卻當成已用過
那就糟了‧‧‧一定會無解!

2007-04-03 07:18:00 · answer #1 · answered by ? 3 · 0 0

我用 Java 寫了一個小程式來解答,但似乎無法求出,要不就是此問題無解,要不就是我的程式有誤。僅將我的程式碼貼上,

import java.util.ArrayList;

public class C {
public static void main(String[] args) {
for (int a = 1; a < 100; a++) {
if (a/10 == a%10) continue;
for (int b = 1; b < 10; b++) {
if (b == a/10 || b == a%10) continue;
int w = a*b;
if (w > 200) continue;
ArrayList al = new ArrayList();
al.add(a/10); al.add(a%10); al.add(b);
int x = w%10;
int y = (w/10)%10;
int z = w/100;
if (x==y || x==z || y==z ||
al.contains(x) || al.contains(y) || al.contains(z)) continue;
al.add(z); al.add(y); al.add(x);

for (int m = 1; m < 99; m++) {
int g = m/10;
int h = m%10;
if (g==h || al.contains(g) || al.contains(h)) continue;
ArrayList al2 = (ArrayList)(al.clone());
al2.add(g); al2.add(h);
int o = w - m;
if (o > 98 || o < 1) continue;
int j = o/10;
int k = o%10;
if (j==k || al2.contains(j) || al2.contains(k)) continue;
System.out.println(a + " " + b + " " + w + " " + m + " " + o);
}
}
}
}
}

2007-03-27 14:20:40 · answer #2 · answered by ? 7 · 0 0

fedest.com, questions and answers