大樂透是從1到49號中,選出6個號碼為一組牌。例如,你可以選擇1,3,5,7,9,11。
從檔案中讀出玩家喜歡的號碼有10個,請輸出這10個號碼組合出所有可能的牌。
在輸出的檔案最後,輸出共有幾組牌。
輸入:in.txt
10,22,31,5,6,11,13,42,1,9
輸出:out.txt
10,22,31,5,6,11
10,22,31,5,6,13
10,22,31,5,6,42
10,22,31,5,6,1
10,22,31,5,6,9
...
共有x組牌
(題外話,完全包牌法是不可行的,下次再來試試所謂的包中3的聰明包牌法,另外還有什麼天才包牌法)
Dim n(10) As Long
回覆刪除Dim ans As Long
Private Sub Form_Load()
Me.Hide
Open App.Path & "\in.txt" For Input As #1
Open App.Path & "\out.txt" For Output As #2
ans = 0
For i = 1 To 10
Input #1, x
n(i) = x
Next
Call abc("", 0)
Print #2, "共有"; ans & "組牌"
Close
Close
End
End Sub
Sub abc(a, b)
If b = 6 Then
Print #2, Left(a, Len(a) - 1): ans = ans + 1
Else
For i = 1 To 10
If InStr(a, n(i)) = 0 Then Call abc(a & n(i) & ",", b + 1)
Next
End If
End Sub
Dim a(9) As Integer
回覆刪除Dim sum As Long
Private Sub Form_Load()
Me.Hide
Open App.Path & "\in.txt" For Input As #1
Open App.Path & "\out.txt" For Output As #2
For I = 0 To 9
Input #1, a(I)
Next I
Call s("", 0)
Print #2, "共有" & sum & "組牌"
Close
Close
End
End Sub
Sub s(x As String, y)
If y = 6 Then
Print #2, Left(x, Len(x) - 1)
sum = sum + 1
Else
For k = 0 To 9
If InStr(x, a(k)) = 0 Then Call s(x & a(k) & ",", y + 1)
Next k
End If
End Sub