某校跳高比賽計(jì)分規(guī)則如下:每個(gè)高度每位選手最多試跳三次,成功記為1,失敗或輪空記為0。如選手第一次試跳成功記為100,第二次試跳成功記為010,第三試跳成功記為001,三次失敗則終止比賽。編寫VB程序統(tǒng)計(jì)選手積分,在文本框Text1中輸入姓名和成績,在列表框List1中輸出結(jié)果,其算法如下:1.將每個(gè)選手的跳高記錄三位一組轉(zhuǎn)換成十進(jìn)制數(shù)存儲(chǔ)到數(shù)組a (該數(shù)組元素的值都不相同)。2.先比較數(shù)組a中各數(shù)組元素的長度,長度長的排名在前;若長度相同的情況下從后往前依次比較字符大小,當(dāng)前數(shù)值大的排名在前。程序運(yùn)行界面如圖所示:
請?jiān)跈M線處填入合適的代碼。
Dim a(1 To 9)As String'存儲(chǔ)跳高成績
Dim b(1 To 9)As String'存儲(chǔ)學(xué)生姓名
Dim c(1 To 9)As Integer
Private Sub Command1_Click ( )
Dim ch As String,tmp As Integer,t As Integer
Dim p As Integer,k As Integer,i As Integer,j As Integer
Dim s As String
s=Text1.Text:t=0
For i=1 To ①
Len(s)或len(jye.ai1.jye.ai)
Len(s)或len(jye.ai1.jye.ai)
If Mid(s,i,1)<>“/“Then
ch=ch+Mid(s,i,1)
Else
t=t+1
If t Mod 2=0 Then
a(t\2)=zh(ch)
Else
②b((t+1)\2)=ch或b(t\2+1)=ch
b((t+1)\2)=ch或b(t\2+1)=ch
End If
ch=““
End If
Next i
For i=1 To t\2
c(i)=i
Next i
For i=1 To t\2-1
p=i
For j=i+1 To t\2
If Len(a(c(p)))<Len(a(c(j)))Then
p=j
ElseIf Len(a(c(j)))=Len(a(c(p)))Then
k=Len(a(j)):flag=True
Do While k>=1 And flag
If Val(Mid(a(c(j)),k,1))>Val(Mid(a(c(p)),k,1))Then
p=j
flag=false
ElseIf val(Mid(a(c(j)),k,1))=val(Mid(a(c(p)),k,1))Then
k=k-1
Else
flag=False
End If
Loop
End If
Next j
If p<>i Then
tmp=c(i):c(i)=c(p):c(p)=tmp
End If
Next i
For i=1 To t\2
③List.Addltem Str(i)+““+b(c(i))+““+a(c(i))
List.Addltem Str(i)+““+b(c(i))+““+a(c(i))
Next i
End Sub
Function zh(cm As String)As String
Dim temp As String
Dim i As Integer,j As Integer
For i=1 To④len(cm)\3
len(cm)\3
For j=1 To 3
temp=temp*2+Val(Mid(cm,(i-1)*3+j,1))
Next j
zh=zh+CStr(temp)'CStr函數(shù)可把表達(dá)式轉(zhuǎn)換為字符串類型
temp=0
Next i
End Function