種(填數字)。 (2)請在畫線處填入合適的代碼。 Const n=2000'物資總項數 Const nc=26'物資種別數,最多不會超過26 Dim items(1 To n)As String,supplies(1 To n)As String,totals(1 To n)As Long Dim g(1 To 2*nc)As Long'存儲各種物資3天、7天的需求數量 Dim b(1 To nc)As Long'存儲各種物資的庫存量 Dim c(1 To nc)As Long Dim q(1 To nc)As Integer Private Sub Form_Load
( )
( )
'本過程讀取編號、品名、收支、需求的數據分別存儲在數組items、supplies、totals、g中,并在List1中顯示有關數據;g數組中g(1)、g(2)存儲物資A的3天、7天的需求數量;g(3)、g(4)存儲物資B的3天、7天的需求數量……代碼略 '代碼略 End Sub Private Sub Command1_Click
( )
( )
Dim i As Integer,j As Integer,k As Integer,top As Integer,bottom As Integer Dim r As Long,s As String,t As Integer,m As Integer For i=1 To nc b(i)=0:c(i)=0 Next i For i=1 To n'統計每種物資的庫存量 k=Asc(Mid(items(i),2,1))-Asc(“A“)+1
b(k)=b(k)+totals(i)
b(k)=b(k)+totals(i)
c(k)=i Next i j=0 For i=1 To nc If c(i)<>0 Then j=j+1:q(j)=i Next i top=0:bottom=j+1 j=1:k=bottom-1 Do While i<bottom '按各種物資的需求量進行等級分類 m=q(j)
r=b(q(j))或r=b(m)
r=b(q(j))或r=b(m)
If r<g(2*m-1)Then top=top+1 If top<>j Then t=q(top):q(top)=q(j):q(j)=t j=j+1 ElseIf r>=g(2*m)Then bottom=bottom-1 t=q(j):q(j)=q(bottom):q(bottom)=t Else j=j+1 End If Loop List2.AddItem“編號 品名 庫存“ List2.AddItem“------“ For i=1 To k s=fp(i,top,bottom) List2.AddItem““& s &““& supplies(c(q(i)))&““& b(q(i)) Next i End Sub Function fp(pos As Integer,head As Integer,tail As Integer)As String If
pos<=head
pos<=head
Then fp=“A“ ElseIf pos<tail Then fp=“B“ Else fp=“C“ End If fp=fp & Mid(items(c(q(pos))),2,1) End Function
1.大部分社交軟件都有好友推薦的功能,當用戶 A 和用戶 B 的共同好友數量超過閾值 p 時,由系統向用戶 A 推薦用戶 B。 編寫 VB 程序,實現好友推薦功能。運行程序,列表框 Listl 中顯示用戶 id 及好友列表,在文本框 Textl 中 輸入推薦目標用戶 id,在文本框 Text2 中輸入閾值 p,點擊“推薦”按鈕,在列表框List2 中顯示用戶之間的關系,在標簽 Label5 中顯示向目標用戶推薦的好友列表。程序運行界面如圖: (1)根據如圖所示數據,若輸入用戶 id 為“3”,輸入閾值為“3”,則推薦好友為: