倍。 (2)根據(jù)上述掃描算法,其 VB 代碼實(shí)現(xiàn)如下,請在橫線處填入合適的代碼。 Dim a(0 To 1000)As Integer'存儲原矩陣數(shù)據(jù),按行優(yōu)先存儲 Dim b(0 To 1000)As Integer'存儲Z形掃描后數(shù)據(jù) Dim c(0 To 1000)As Integer'存儲行程編碼壓縮后數(shù)據(jù) Dim n As Integer ‘矩陣導(dǎo)入代碼略,以行優(yōu)先存儲在a數(shù)組中,如例子中數(shù)據(jù)存儲順序?yàn)椤?7,45,0,23,0,0…” Private Sub Command2_Click ( ?。?br />Dim choice As Integer'1:向右移動;2:向右上移動;3向下移動 4向左下移動 Dim row As Integer,col As Integer,i As Integer,j As Integer Dim pre As Integer,count As Integer choice=1:row=0:col=0:i=0 Do While (row<>n-1 Or col<>n-1) b(i)=a(row*n+col):i=i+1 If choice=1 Then
col=col+1
col=col+1
If row=0 Then choice=4 Else choice=2 ElseIf choice=2 Then row=row-1:col=col+1 If
row=0 And col<>n-1
row=0 And col<>n-1
Then choice=1 ElseIf col=n-1 Then choice=3 End If ElseIf choice=3 Then row=row+1 If col=0 Then choice=2 Else choice=4 ElseIf choice=4 Then row=row+1:col=col-1 If row=n-1 Then choice=1 ElseIf col=0 Then choice=3 End If End If Loop b(i)=a(n*n-1):j=0:pre=b(0):count=0 For i=0 To n*n-1'輸出Z形序列,并進(jìn)行行程壓縮 If pre=b(i)Then count=count+1 Else c(j)=pre:c(j+1)=count
count=1
count=1
pre=b(i):j=j+2 End If Next i c(j)=pre:c(j+1)=count Text1.Text=““ For i=0 To j+1 Text1.Text=Text1.Text+Str(c(i))+“,“ Next i End Sub
1.大部分社交軟件都有好友推薦的功能,當(dāng)用戶 A 和用戶 B 的共同好友數(shù)量超過閾值 p 時,由系統(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”,則推薦好友為: