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, D Line Input #1, X List1.Clear: List2.Clear For I = 1 To N List1.AddItem Mid(X, I, 1) Next I
Call ABC(N - D, "", -1)
Print #2, List2.List(List2.ListCount - 1)
Loop Close #2 Close #1 End End Sub
Sub ABC(A, B, C) If Len(B) = A Then List2.AddItem B Else For I = 0 To List1.ListCount - 1 If I > C Then Call ABC(A, B & List1.List(I), I) Next I End If End Sub
Dim max, ans, s(), TT 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 Line Input #1, m ReDim s(Len(m)) For i = 1 To Len(m) s(i) = Mid(m, i, 1) Next
ans = "" For j = (n - k) - 1 To 0 Step -1 max = 0 For i = 1 To UBound(s) - j If s(i) > max Then max = s(i): TT = i Next ans = ans & max s(TT) = 0 Next
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, D
Line Input #1, X
List1.Clear: List2.Clear
For I = 1 To N
List1.AddItem Mid(X, I, 1)
Next I
Call ABC(N - D, "", -1)
Print #2, List2.List(List2.ListCount - 1)
Loop
Close #2
Close #1
End
End Sub
Sub ABC(A, B, C)
If Len(B) = A Then
List2.AddItem B
Else
For I = 0 To List1.ListCount - 1
If I > C Then Call ABC(A, B & 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 max, ans, s(), TT
回覆刪除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
Line Input #1, m
ReDim s(Len(m))
For i = 1 To Len(m)
s(i) = Mid(m, i, 1)
Next
ans = ""
For j = (n - k) - 1 To 0 Step -1
max = 0
For i = 1 To UBound(s) - j
If s(i) > max Then max = s(i): TT = i
Next
ans = ans & max
s(TT) = 0
Next
Print #2, ans
Loop
Close
Close
End
End Sub