Dim s 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) List1.Clear nn = "" Input #1, a, b Input #1, n
c = a - b
For i = 1 To Len(n) nn = nn & " " & Mid(n, i, 1) Next
s = Split(nn)
Call Q("", c, 0)
ou = List1.List(List1.ListCount - 1) Do ou = Right(ou, Len(ou) - 1) Loop Until Left(ou, 1) <> 0
Print #2, ou Loop Close Close End End Sub
Function Q(ans As String, a, m)
If Len(ans) = a Then
Do Until Len(ans) = 10 ans = "0" & ans Loop List1.AddItem ans
Else For i = 0 To UBound(s) If m < i Then Call Q(ans & s(i), a, i) Next End If
Dim X As String Dim N As Byte Dim B As Byte Dim ans 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) Input #1, N, K Input #1, SN X = CStr(SN) N = N - K '需要幾個 A = 9 ans = ""
Do
B = Find_b(A)
Select Case B Case Is = N: ans = ans & Right(X, B) Case Is < N: A = A - 1 Case Is > N: X = Right(X, B - 1): ans = ans & CStr(A): N = N - 1: A = 9 End Select
Loop Until N = 0 Or N = B
Print #2, ans
Loop Close #2 Close #1
End End Sub
Function Find_b(A) If InStr(X, A) <> 0 Then Find_b = (Len(X) - InStr(X, A) + 1) End Function
Open App.Path & "\in.txt" For Input As #1 Open App.Path & "\out.txt" For Output As #2
Do While Not EOF(1) List1.Clear List2.Clear Input #1, N, K Input #1, A
For i = 1 To Len(A) List1.AddItem Mid(A, i, 1) Next i
Call ABC("", 0)
Print #2, List2.List(List2.ListCount - 1) Loop Close #2 Close #1
End End Sub
Sub ABC(X, ByVal Y) If Len(X) = N - K Then List2.AddItem X Else For i = 0 To (List1.ListCount - 1) If InStr(X, List1.List(i)) = 0 And i >= Y Then Call ABC(X & List1.List(i), i) Next i End If End Sub
Open App.Path & "\in.txt" For Input As #1 Open App.Path & "\out.txt" For Output As #2
Do While Not EOF(1) List1.Clear List2.Clear Input #1, N, K Input #1, A
For i = 1 To Len(A) List1.AddItem Mid(A, i, 1) Next i
Call ABC("", -1)
Print #2, List2.List(List2.ListCount - 1) Loop Close #2 Close #1
End End Sub
Sub ABC(X, ByVal Y) If Len(X) = N - K Then List2.AddItem X Else For i = 0 To (List1.ListCount - 1) If i > Y Then Call ABC(X & List1.List(i), i) Next i End If End Sub -------------------------------- in.txt 6 4 268574 7 3 9977789 6 3 929987 -------------------------------- out.txt 87 9989 999
Dim s
回覆刪除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)
List1.Clear
nn = ""
Input #1, a, b
Input #1, n
c = a - b
For i = 1 To Len(n)
nn = nn & " " & Mid(n, i, 1)
Next
s = Split(nn)
Call Q("", c, 0)
ou = List1.List(List1.ListCount - 1)
Do
ou = Right(ou, Len(ou) - 1)
Loop Until Left(ou, 1) <> 0
Print #2, ou
Loop
Close
Close
End
End Sub
Function Q(ans As String, a, m)
If Len(ans) = a Then
Do Until Len(ans) = 10
ans = "0" & ans
Loop
List1.AddItem ans
Else
For i = 0 To UBound(s)
If m < i Then Call Q(ans & s(i), a, i)
Next
End If
End Function
arro好,
回覆刪除程式有小錯誤,那個設定長度最長為10,為何不用a呢。
還是先算20分,但是,再說一次,這樣的小錯誤,到時候是會哭的。
Dim X As String
回覆刪除Dim N As Byte
Dim B As Byte
Dim ans 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)
Input #1, N, K
Input #1, SN
X = CStr(SN)
N = N - K '需要幾個
A = 9
ans = ""
Do
B = Find_b(A)
Select Case B
Case Is = N: ans = ans & Right(X, B)
Case Is < N: A = A - 1
Case Is > N: X = Right(X, B - 1): ans = ans & CStr(A): N = N - 1: A = 9
End Select
Loop Until N = 0 Or N = B
Print #2, ans
Loop
Close #2
Close #1
End
End Sub
Function Find_b(A)
If InStr(X, A) <> 0 Then Find_b = (Len(X) - InStr(X, A) + 1)
End Function
老師寫的演算法,再複習一次。
用自己的方法寫,
回覆刪除list2 屬性 Sorted = True
老師明天早上我要去頒獎無法過去練習。
Dim N As Long
Dim K 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
Do While Not EOF(1)
List1.Clear
List2.Clear
Input #1, N, K
Input #1, A
For i = 1 To Len(A)
List1.AddItem Mid(A, i, 1)
Next i
Call ABC("", 0)
Print #2, List2.List(List2.ListCount - 1)
Loop
Close #2
Close #1
End
End Sub
Sub ABC(X, ByVal Y)
If Len(X) = N - K Then
List2.AddItem X
Else
For i = 0 To (List1.ListCount - 1)
If InStr(X, List1.List(i)) = 0 And i >= Y Then Call ABC(X & List1.List(i), i)
Next i
End If
End Sub
佑好,
回覆刪除第1個程式ok,
但是第2個程式中,倒數第5行,的InStr(X, List1.List(i)) = 0,如果給的數字是有很多重複的呢?像是
6 3
929987
熊掌好,已解決
回覆刪除謝老師。
Dim N As Long
Dim K 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
Do While Not EOF(1)
List1.Clear
List2.Clear
Input #1, N, K
Input #1, A
For i = 1 To Len(A)
List1.AddItem Mid(A, i, 1)
Next i
Call ABC("", -1)
Print #2, List2.List(List2.ListCount - 1)
Loop
Close #2
Close #1
End
End Sub
Sub ABC(X, ByVal Y)
If Len(X) = N - K Then
List2.AddItem X
Else
For i = 0 To (List1.ListCount - 1)
If i > Y Then Call ABC(X & List1.List(i), i)
Next i
End If
End Sub
--------------------------------
in.txt
6 4
268574
7 3
9977789
6 3
929987
--------------------------------
out.txt
87
9989
999
佑好,
回覆刪除先祝一聲暑假快樂。
這一題正確。
暑假至少要一星期5題哦,當然是多多益善。
如果找不到題目,可以留言說一下哦。
另外,我應該7/21、22會到學校,也可以那時候去學校問問題哦。
(飛往遠方的熊掌)