VB代码实现如下,请在划线处填入合适的代码。
Dim n As Integer, m As Integer
Dim a(1 To 20) As Integer, b(1 To 20) As Integer
Private Sub Form_ Load()
'读取卖家人数n以及最低卖出价格,存入数组元素a(1)到a(n)中;
'读取买家人数m以及最高买入价格,存入数组元素b(1)到b(m)中;
'代码略
End Sub
Private Sub Command1_Click()
Dim i As Integer, L As Integer, R As Integer
Dim ml As Integer, m2 As Integer, sI As Integer, s2 As Integer
Dim price1 As Integer, price2 As Integer
Dim tot1 As Integer, tot2 As Integer
Dim mini As Integer, maxi As Integer
mini = a(1): maxi = ' mini 和maxi分别为可交易的最低价和最高价
For i=2 To n
If mini > a(i) Then mini = a(i)
Next i
For i=2 To m
If maxi < b(i) Then maxi = b(i)
Next i
L=mini:R=maxi
Do While L<R
s1 =0:s2= 0
m1=(L+R+1)\2
For i=1 To n
If a(i)<=m1 Then s1=s1+1
Next i
For i=1 To m
If b(i)>=m1 Then s2=s2+1
Next i
If s1>s2 Then Else L=m1
Loop
price1=L: tot1 = s1 'price1和tot1分别为价格和交易人数
L=mini:R=maxi
Do While L<R
s1 =0:s2=0
m2=(L+R)\2
For i =1 To n
If a(i) <= m2 Then s1=s1 + 1
Next i
For i=1 To m
If b(i) >= m2 Then s2=s2+1
Next i
If s1<s2 Then L=m2+1 Else R=m2
Loop
price2 = L: tot2 = s2 ' price2和tot2分别为价格和交易人数
If Then
Label3.Caption ="最终定价为" + Str(price1) + "元"
End If
End Sub