網路城邦
回本城市首頁 唐老鴨之家
市長:  副市長:
加入本城市推薦本城市加入我的最愛訂閱最新文章
udn城市資訊科技網路分享【唐老鴨之家】城市/討論區/
討論區Excel VBA 字體:
上一個討論主題 回文章列表 下一個討論主題
益智問題求解之一
 瀏覽928|回應0推薦0


等級:6
留言加入好友
 □□
╳ □
────
 □□
+□□
────
 □□

□中填入1,2,3,...,9,不可重複,可知答案為何? (17, 4, 68, 25, 93為唯一解)


Dim selected(10) As Boolean
Private Sub CommandButton1_Click()
For X = 12 To 98
For Y = 2 To 9
For Z = 12 To 98
For i = 1 To 9
selected(i) = False
Next i
If (check(Int(X / 10))) Then GoTo nnext
If (check(X Mod 10)) Then GoTo nnext
If (check(Y)) Then GoTo nnext
t1 = X * Y
If (t1 > 99) Then GoTo nnext
If (check(Int(t1 / 10))) Then GoTo nnext
If (check(t1 Mod 10)) Then GoTo nnext
If (check(Int(Z / 10))) Then GoTo nnext
If (check(Z Mod 10)) Then GoTo nnext
t2 = t1 + Z
If (t2 > 99) Then GoTo nnext
If (check(Int(t2 / 10))) Then GoTo nnext
If (check(t2 Mod 10)) Then GoTo nnext
Cells(1, 1) = X
Cells(2, 1) = Y
Cells(3, 1) = X * Y
Cells(4, 1) = Z
Cells(5, 1) = X * Y + Z
nnext:
Next Z
Next Y
Next X
End Sub

Function check(numb)
If (selected(numb)) Then
check = True
Else
selected(numb) = True
check = False
End If
End Function

本文於 修改第 2 次
回應 回應給此人 推薦文章 列印 加入我的文摘

引用
引用網址:https://city.udn.com/forum/trackback.jsp?no=58536&aid=5469269