Dim N As Integer Dim Y() As String Private Sub Form_Load() Me.Hide Open App.Path & "\in.txt" For Input As #1 Open App.Path & "\out.txt" For Output As #2 Do While Not EOF(1) Line Input #1, X Y = Split(X) Input #1, N Call ABC("", 0) Loop Close #2 Close #1 End End Sub
Sub ABC(A, B) If Len(A) = N Then Print #2, A Else For i = B To UBound(Y) If InStr(A, Y(i)) = 0 Then Call ABC(A & Y(i), i + 1) Next i End If End Sub
Dim n As String, s, m Private Sub Form_Load() Me.Hide Open App.Path & "\in.txt" For Input As #1 Open App.Path & "\out.txt" For Output As #2 Input #1, n Input #1, m s = Split(n) Call Fun("", 0) Close Close End End Sub
Function Fun(a, b) If Len(a) = m Then Print #2, a Else For i = b To UBound(s) If InStr(a, s(i)) = 0 Then Call Fun(a & s(i), i + 1) Next End If End Function
原本以為1X 與 X1 不同
回覆刪除看了輸出範例才知道...
Dim N As Integer
Dim Y() As String
Private Sub Form_Load()
Me.Hide
Open App.Path & "\in.txt" For Input As #1
Open App.Path & "\out.txt" For Output As #2
Do While Not EOF(1)
Line Input #1, X
Y = Split(X)
Input #1, N
Call ABC("", 0)
Loop
Close #2
Close #1
End
End Sub
Sub ABC(A, B)
If Len(A) = N Then
Print #2, A
Else
For i = B To UBound(Y)
If InStr(A, Y(i)) = 0 Then Call ABC(A & Y(i), i + 1)
Next i
End If
End Sub
佑好
回覆刪除這樣的遞迴,很好。
繼續練習。
Dim n As String, s, m
回覆刪除Private Sub Form_Load()
Me.Hide
Open App.Path & "\in.txt" For Input As #1
Open App.Path & "\out.txt" For Output As #2
Input #1, n
Input #1, m
s = Split(n)
Call Fun("", 0)
Close
Close
End
End Sub
Function Fun(a, b)
If Len(a) = m Then
Print #2, a
Else
For i = b To UBound(s)
If InStr(a, s(i)) = 0 Then Call Fun(a & s(i), i + 1)
Next
End If
End Function
佑你的DOLOOP是不是算多餘的阿?
YES,
回覆刪除做上一題
接著做題目:P
謝摟
忘了改名字 ...
回覆刪除