種。 (2)實現上述功能的 VB 程序如下,運行結果如圖所示,請在橫線處填入合適的代碼。 Private Sub Command1_Click( ?。?br />Dim n As Integer,t As Integer,i As Integer,j As Integer,k As Integer Dim flag as Boolean,ans As Integer Dim a(1 To 15)As Integer n=Val(Text1.Text) For i=0 To 2^n-1 t=i For j=1 To n a(j)=t Mod 2 t=t\2 Next j flag=True For k=1 To n-1 If①Then flag=False Next k If flag Then②:ans=ans+1 Next i Label3.Caption=″可能方案共″+Str(ans)+″種″ End Sub Function GetStr(x As Integer,n As Integer) As String Dim m As Integer,i As Integer GetStr=″″ m=x For i=1 To n If m Mod 2=0 Then GetStr=″A″+GetStr Else GetStr=″B″+GetStr End If ③ Next i End Function
1.大部分社交軟件都有好友推薦的功能,當用戶 A 和用戶 B 的共同好友數量超過閾值 p 時,由系統向用戶 A 推薦用戶 B。 編寫 VB 程序,實現好友推薦功能。運行程序,列表框 Listl 中顯示用戶 id 及好友列表,在文本框 Textl 中 輸入推薦目標用戶 id,在文本框 Text2 中輸入閾值 p,點擊“推薦”按鈕,在列表框List2 中顯示用戶之間的關系,在標簽 Label5 中顯示向目標用戶推薦的好友列表。程序運行界面如圖: (1)根據如圖所示數據,若輸入用戶 id 為“3”,輸入閾值為“3”,則推薦好友為: