從檔案 in.txt 讀入排列組合的項目,將所有可能的排列輸出到out.txt。
輸入範例:
a b c 1
輸出範例:
abc1
bac1
cab1
1abc
acb1
a1bc
bca1
b1ac
cba1
c1ab
1bac
1cab
ab1c
ba1c
ca1b
1acb
ac1b
a1cb
bc1a
b1ca
cb1a
c1ba
1bca
1cba
Dim strr
回覆刪除Private Sub Form_Load()
Open App.Path & "\in.txt" For Input As #1
Open App.Path & "\out.txt" For Output As #2
Input #1, strr
strr = Split(strr, " ")
Call rr("")
Close #2
Close #1
End Sub
Public Function rr(k As String)
If Len(k) = (UBound(strr) + 1) Then
Print #2, k
Else
For i = 0 To UBound(strr)
If InStr(k, strr(i)) = 0 Then Call rr(k & strr(i))
Next
End If
End Function
Dim n
回覆刪除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
Call a("")
Close #2
Close #1
End
End Sub
Public Function a(c) As String
If Len(n) = Len(c) Then
Print #2, c
Else
For i = 1 To Len(n)
If InStr(c, Mid(n, i, 1)) = 0 Then Call a(c & Mid(n, i, 1))
Next
End If
End Function
Dim a() 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
Input #1, x
a = Split(x, " ")
Call b("")
Close #2
Close #1
End
End Sub
Sub b(c)
If Len(c) = UBound(a) + 1 Then
Print #2, c
Else
For i = 0 To UBound(a)
If InStr(c, a(i)) = 0 Then Call b(c & a(i))
Next i
End If
End Sub