這台機器有三顆功能鍵跟數字小鍵盤
功能鈕上分別寫著
1. Insert
2. Query MAX
3. Query MIN
旁邊寫著一行粗字: 極值經查詢後將會刪除
題目看到這各位也明瞭了吧
請你寫出這台機器的程式
可以插入數字並且查詢其中的最大值與最小值
輸入說明 :
每行輸入開頭有三種情形
1: 插入操作,其後會跟著一數字 N 代表插入的數字 (0 ≤ N ≤ 2^31-1)
2: 查詢最大值
3: 查詢最小值
同一時間內最多有 100,0000 個數字
輸出說明 :
每筆查詢輸出一行
每行只有一個數字
範例輸入 :
1 3
1 100
2
1 4
3
範例輸出 :
100
3
Dim max, min As Long
回覆刪除Dim strr As String
Private Sub Form_Load()
Me.Hide
max = 0
min = 99999
Open App.Path & "\in.txt" For Input As #1
Open App.Path & "\out.txt" For Output As #2
Do
Line Input #1, strr
num = Split(strr, " ")
Select Case Val(num(0))
Case Is = 1
If Val(num(1)) > max Then max = Val(num(1))
If Val(num(1)) < min Then min = Val(num(1))
Case Is = 2
Print #2, max
max = 0
Case Is = 3
Print #2, min
min = 99999
End Select
Loop Until EOF(1)
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
Input #1, n
Select Case n
Case Is = 1
Input #1, x
List1.AddItem Val(x) + 10 ^ 10
Case Is = 2
s = List1.ListCount - 1
b = List1.List(s) - 10 ^ 10
'For i = 0 To List1.ListCount
'MsgBox List1.List(i)
'Next
Print #2, b
List1.RemoveItem (s)
Case Is = 3
m = List1.List(0) - 10 ^ 10
Print #2, m
List1.RemoveItem (0)
End Select
Loop Until EOF(1)
Close #2
Close #1
End
End Sub