Option Explicit
'从0到9的数字组成一道一位数加两位数加三位数得四位数的算式不得重复数字
Dim b(9), a(9)
Private Sub Command1_Click()
Dim i
For i = 0 To 9
b(i) = i: a(i) = 10
Next i
dg 0, a
End Sub
Sub dg(t, ByVal a)
Dim i, j, t1
If t > 9 Then
If a(0) + a(1) * 10 + a(2) + a(3) * 100 + a(4) * 10 + a(5) = a(6) * 1000 + a(7) * 100 + a(8) * 10 + a(9) Then
Debug.Print a(0) & "+" & (a(1) * 10 + a(2)) & "+" & (a(3) * 100 + a(4) * 10 + a(5)) & " = " & (a(6) * 1000 + a(7) * 100 + a(8) * 10 + a(9))
End If
Exit Sub
Else
If t = 1 Or t = 3 Or t = 6 Then t1 = 1 Else t1 = 0
For i = t1 To 9
For j = 0 To t - 1
If i = a(j) Then Exit For
Next j
If j = t Then
a(t) = i: dg t + 1, a
End If
Next i
End If
DoEvents
End Sub