Problem2:(11%)
有一個n位數的正整數A,請問刪除其中k個連續或不連續的位數 (k <n)、將剩下的數字依序合併形成一個新的正整數B,B的最大可能值是多少?(請注意,A和B的首位都不能是0)。
輸入說明:
奇數列有兩個以空白隔開的正整數n及k (1 ≤ k < n ≤ 1000000)。偶數列會有一個長度為n的正整數A。
輸出說明:
請輸出B的最大可能值。
輸入範例:
6 4
268574
5 2
41235
輸出範例:
87
435
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, n1
Input #1, x
b = n - n1
ans = ""
a = 0
Do
b = b - 1
Max = 0
For i = a + 1 To n - b
If Mid(x, i, 1) > Max Then Max = Mid(x, i, 1): a = i
Next
ans = ans & Max
Loop Until b = 0
Print #2, ans
Loop
Close
Close
End
End Sub
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, A
B = ""
x = n - k
y = 0
Do Until x = 0
Max = 0
x = x - 1
For i = y + 1 To n - x
If Mid(A, i, 1) > Max Then Max = Mid(A, i, 1): y = i
Next i
B = B & Max
Loop
Print #2, B
Loop
Close #2
Close #1
End
End Sub
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, x, y
Input #1, z
l = Val(x) - Val(y)
Do Until Len(z) = l
min1 = 99
For i = 1 To Len(z)
If Val(Mid(z, i, 1)) < min1 Then min1 = Mid(z, i, 1)
Next i
z = Replace(z, min1, "")
Loop
Print #2, z
Loop
Close #2
Close #1
End
End Sub