倍。 (2)根據上述掃描算法,其 VB 代碼實現如下,請在橫線處填入合適的代碼。 Dim a(0 To 1000)As Integer'存儲原矩陣數據,按行優先存儲 Dim b(0 To 1000)As Integer'存儲Z形掃描后數據 Dim c(0 To 1000)As Integer'存儲行程編碼壓縮后數據 Dim n As Integer ‘矩陣導入代碼略,以行優先存儲在a數組中,如例子中數據存儲順序為“57,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形序列,并進行行程壓縮 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.大部分社交軟件都有好友推薦的功能,當用戶 A 和用戶 B 的共同好友數量超過閾值 p 時,由系統向用戶 A 推薦用戶 B。 編寫 VB 程序,實現好友推薦功能。運行程序,列表框 Listl 中顯示用戶 id 及好友列表,在文本框 Textl 中 輸入推薦目標用戶 id,在文本框 Text2 中輸入閾值 p,點擊“推薦”按鈕,在列表框List2 中顯示用戶之間的關系,在標簽 Label5 中顯示向目標用戶推薦的好友列表。程序運行界面如圖: (1)根據如圖所示數據,若輸入用戶 id 為“3”,輸入閾值為“3”,則推薦好友為: