。 (2)實(shí)現(xiàn)上述功能的VB程序如下,運(yùn)行結(jié)果如圖所示,請(qǐng)?jiān)跈M線處填入合適的代碼。 Private Sub Commandl_Click( ?。?br />Dim d(1 To 2)As Integer i As Integer,j As Integer Dim s As String.jye.ai As Integer,s2 As Integer,t As Integer s= Textl.Text:s1=0:s2=0:j=I For i=1 To len (s)c= Mid(s,i,I)If c<> “?”Then if i Mod 2=0 Then sl=sl+Val(c)Else s2=s2+Val(c) Else
j=j+1 End If Next i Listl Clear For i=0 To 9 For j=0 To 9 t= If (s1-s2+i+j)Mod 3=0 And t Mod 1I=0 Then s=Sreplace(s,d(1),i) s=Sreplace(s,d(2),j) Listl.AddItem s End If Next j Next i End Sub 函數(shù) Sreplace的返回值字符串中要求沒有空格 Function Sreplace(s As String,x As Integer,y As Integer)As String Sreplace =Mid(s,1,x-1)+ End Function
1.大部分社交軟件都有好友推薦的功能,當(dāng)用戶 A 和用戶 B 的共同好友數(shù)量超過(guò)閾值 p 時(shí),由系統(tǒng)向用戶 A 推薦用戶 B。 編寫 VB 程序,實(shí)現(xiàn)好友推薦功能。運(yùn)行程序,列表框 Listl 中顯示用戶 id 及好友列表,在文本框 Textl 中 輸入推薦目標(biāo)用戶 id,在文本框 Text2 中輸入閾值 p,點(diǎn)擊“推薦”按鈕,在列表框List2 中顯示用戶之間的關(guān)系,在標(biāo)簽 Label5 中顯示向目標(biāo)用戶推薦的好友列表。程序運(yùn)行界面如圖: (1)根據(jù)如圖所示數(shù)據(jù),若輸入用戶 id 為“3”,輸入閾值為“3”,則推薦好友為: