编写VB程序,实现上述挑选功能。运行程序,在文本框Text1中输入参数h后,单击“挑选”按钮Command1,在列表框List1中按QA值降序显示满足条件一的申请人信息,最后在标签Label1中显示组队结果。程序运行界面如图所示。
请回答下列问题:
Const m = 20 'm表示申请人个数
Dim id(m)As Integer, qa(m)As Integer, qb(m)As Integer
Private Sub Command1_Click( )
Dim i As Integer j As Integer, k As Integer, t As Integer, max As Integer
Dim h As Integer, n As Integer '变量n存储满足条件一的申请人个数
Dim s As String
'读取全部申请人的编号、QA和QB值,分别存入数组id、qa和qb,代码略
h = Val(Text1. Text):n = m
For i = 1 To m — 1
k = i
For j = i + 1 To m
If qa(j)> qa(k)Then k = j
Next j
If Then
If k <> i Then
t = qa(i):qa(i) = qa(k):qa(k) = t
t = qb(i):qb(i) = qb(k):qb(k) = t
t = id(i):id(i) = id(k):id(k) = t
End If
Else
n =
Exit For 'Exit For表示退出循环
End If
Next i
'满足条件一的申请人信息显示在列表框Listl中,代码略
max = 0:s = “没有满足条件的组合”
'在满足条件的组合中,寻找QB值之和最大的组合,若有并列,只保留第一个
For i = n To 2 Step - 1
j = i - 1
Do While
If qb(i)+ qb(j) > max Then
s = "组队结果:" + Str(id(i)) + "号," + Str(id(j)) + "号"
End If
j = j - 1
Loop
Next i
Label1. Caption = s
End Sub