。(分數用逗號隔開) (2)請在橫線處完成代碼填空。 Dim a(1 To 100)Integer,b(1 To 100)As Integer Dim num(1 To 100)As Integer,win(1 To 100)As Integer,lose(1 To 100)As Integer Dim win_num As Integer,lose_num As Integer Dim As Integer,r As Integer,s1 As String,As String,53 As String Private Sub Command1_Click ____ 讀取已打亂的隊伍信息,編號、實力分別存在數組num和數組a中,且將數組b置0 代碼略 End Sub Private Sub Command2_Click ____ Dim i As Integer,j As Integer,t As Integer ori=1 To Step2 先比第一輪 If a(i)>a(+1)Then b(i)=1 Else ____ Next i For i=1Ton-1 將第一輪結果排序 For j=1 Ton-i If cmp(
b(i+1)=1
b(i+1)=1
) Then t=num(j):num(j)=num(j+1):num(j+1)=t End If Next j Next i For i=1 To r-1'比剩下的 r-1 輪比賽 win_num=0:lose_num=0 For j=1 To n Step 2 win_num=win_num+1:lose_num=lose_num+1 If a(num(j))>a(num(j+1)) Then b(num(j))=b(num(j))+1 win(win_num)=num(j):lose(lose_num)=num(j+1) Else b(num(j+1))=b(num(j+1))+1 win(win_num)=num(j+1):lose(lose_num)=num(j) End If Next j Call merge'調用過程,合并勝利組和失敗組Next i s1=“編號:“:s2=“分數:“ For i=1 To n s1=s1+format(num(i)) s2=s2+format(
cmp(num(j+1),mun(j))
cmp(num(j+1),mun(j))
) Next i List2.AddItem s1 List2.AddItem s2 End Sub Sub merge
b(mum(i))
b(mum(i))
'合并過程 '將勝利組與失敗組按照分數合并,生成下一輪比賽順序并存回數組 num 中 '代碼略End Sub Function format(x As Integer) As String'格式化字符串函數'將輸入數字格式化為 3 個字符長度,代碼略 End Function Function cmp(i As Integer,j As Integer) As Boolean'比較函數cmp=False If b(i)=b(j) Then If i<j Then cmp=True ElseIf b(i)>b(j) Then cmp=True End If End Function
1.大部分社交軟件都有好友推薦的功能,當用戶 A 和用戶 B 的共同好友數量超過閾值 p 時,由系統向用戶 A 推薦用戶 B。 編寫 VB 程序,實現好友推薦功能。運行程序,列表框 Listl 中顯示用戶 id 及好友列表,在文本框 Textl 中 輸入推薦目標用戶 id,在文本框 Text2 中輸入閾值 p,點擊“推薦”按鈕,在列表框List2 中顯示用戶之間的關系,在標簽 Label5 中顯示向目標用戶推薦的好友列表。程序運行界面如圖: (1)根據如圖所示數據,若輸入用戶 id 為“3”,輸入閾值為“3”,則推薦好友為: