实现上述功能的VB程序如下,请在划线处填入合适代码。
Const n = 9
'数组 xh、df 和 mc 分别存储选手编号、得分和名次;df 数组的 1~n 元素存储笔试相关数据;n+1~2n 元素存储对应选手的面试相关数据;2n+1~3n 元素存放两项考试总分相关数据
Dim xh(1 To n * 3) As Integer, df(1 To n * 3) As
Integer, mc(1 To n * 3) As Integer
Dim i As Integer, j As Integer, t As Integer
'本过程从数据库读取各选手的选手编号、得分数据,分别存储在数组 xh、df 中
Private Sub Form_Load( )
List1.Clear
List1.AddItem
"选手" + " " + "笔试" + " " + "面试"
For i = 1 To
n
xh(i) = i: xh(n + i) = i
Next i
For i = 1 To
n
List1.AddItem Str(xh(i)) + " " +
Str(df(i)) + " " + Str(df(n + i))
Next i
End Sub
Private Sub Command1_Click()
Dim c As
Integer
c =
Val(Text1.Text)
Label1.Caption = "笔试前" & Str(c) & "名:" & pm(1, n, c, False)
Label2.Caption = "面试前" & Str(c) & "名:" & pm(n + 1, 2 * n, c, False)
For i = 1 To
n
xh(2 * n + i) = i: df(2 * n + i) = 0: mc(2 * n
+ i) = 0
Next i
For i = 1 To
2 * n
df(2 *
n + xh(i)) = df(2 * n + xh(i)) + mc(i)
Next i
Label3.Caption = "总分前" & Str(c) & "名:" & pm
End Sub
Function pm(ks As Integer, js As Integer, num As
Integer, fx As Boolean) As String
For i = ks To
js - 1
For j = js To ks + 1 Step -1
If (fx And df(j) < df(j - 1)) OrThen
t = df(j): df(j) = df(j - 1): df(j - 1) = t
t = xh(j): xh(j) = xh(j - 1): xh(j - 1) = t
End If
Next j
Next i
mc(ks) = 1:
pm = Str(xh(ks))
For i = ks +
1 To js
If df(i) = df(i - 1) Then
Else
mc(i) = i - ks + 1
End If
If mc(i)
<= num Then pm = pm & "," & Str(xh(i))
Next i
End Function