。 (2)請在橫線處①②③填入合適的代碼。 (3)程序中加框處代碼有誤,請修改。 Dim weight(1 To 100)As Integer Dim t As Integer Private Sub Boat_Click ( ) Dim s As String Dim d As Integer Dim max,sum As Integer Dim L,R As Integer Dim m As Integer s=Text1.Text d=Val(Text2.Text) t=1 '將貨物重量存到weight數組 For i=1 To Len(s) c=Mid(s,i,1) If c=“,“Then t=t+1 Else①
weight(t)=weight(t)*10+Val(c)
weight(t)=weight(t)*10+Val(c)
Next i '求貨物最大重量和總重量 max=0 For i=1 To t-1 If weight(i)>max Then max=weight(i) ②
sum=sum+weight(i)
sum=sum+weight(i)
Next i L=max:R=sum Do While L<R m=(L+R)\2 If③
days(m)<=d
days(m)<=d
Then R=m Else L=m+1 Loop Label1.Caption=“貨船最低載重量為:“+Str(L) End Sub Function days(m As Integer)As Integer Dim temp As Integer Dim c As Integer c=1 For i=1 To t-1 temp=temp+weight(i) If temp>m Then temp=0 c=c+1 End If Next i days=c End Function
1.大部分社交軟件都有好友推薦的功能,當用戶 A 和用戶 B 的共同好友數量超過閾值 p 時,由系統向用戶 A 推薦用戶 B。 編寫 VB 程序,實現好友推薦功能。運行程序,列表框 Listl 中顯示用戶 id 及好友列表,在文本框 Textl 中 輸入推薦目標用戶 id,在文本框 Text2 中輸入閾值 p,點擊“推薦”按鈕,在列表框List2 中顯示用戶之間的關系,在標簽 Label5 中顯示向目標用戶推薦的好友列表。程序運行界面如圖: (1)根據如圖所示數據,若輸入用戶 id 為“3”,輸入閾值為“3”,則推薦好友為: