n=Val(Text1.Text)
s=""
flag=True
Do While n>0
⑴
n=n\10
If Not flag Or x>0 Then
⑵
flag=False
End If
Loop
If s="" Then s ="0"
Labe 11.Caption=s
方框中(1)和(2)应填入的代码顺序为( )
①x=nMod10^len(n) ②x=nMod10 ③s=Str(x)+s ④s=s+Str(x)
s="olympicGames2021"
ans=""
i=1
Do While i<=Len(s)
t=Int(Rnd *2)+1
x=Mid(s,i,1)
y=Mid(s,i+t,1)
If x>y Then an s=ans+x Else ans=ans+y
i=i+t+1
Loop
Label1.Caption=ans
执行该程序段后,标签Labe11上显示的内容不可能为( )
i=1:j=25
n=0
Do While i<=j
m=(i+j+1)\2
n=n+1
If key=a(m)Then Exit Do
If key>a(m)Then i=m+1Elsej=m-1
Loop
Labe11.Caption=Str(n)
数组元素a(1)~a(25)的值依次为1~25,若查找键key为下列选项的值,程序段执行后,标签Label1中显示的内容与其他三项不同的是( )
For i=1 To n-1 Step 2
For j=1To((n+1)\2)*2-i-2 Step 2
If a(j)>a(j+2)Then
t=a(j):a(j)=a(j+2):a(j+2)=t
End If
Next j
For j= ①
If a(j)>a(j-2)Then
t=a(j):a(j)=a(j-2):a(j-2)=t
End If
Next j
Next i
执行该程序段后,实现了对数组元素a(1)~a(n)中的奇数位置从小到大排序,偶数位置从大到小排序。则代码中①处的语句可为( )
图b
图c |
图b |
请回答下列问题:
Const n=40
Const k=5
Dim f(1 To 500)As String
Dim sum As Integer
Private Sub Form_Load()
'读取sum张纸的信息,存入到数组f并显示在列表框List1中,代码略
End Sub
Private Sub Command1_Click()
Dim i As Integer,j As Integer,t As Integer,tmp As Integer
Dim a(500)As Integer,b(500)As Integer
Dim c(500)As Integer,d(500)As Integer
'读取每张纸信息,将页码存入到a数组中,活页本编号存入到b数组中
For i=1 To sum
a(i)=Val(Mid(f(i),4))
b(i)=
Next i
For i=1 To sum-1 '对每一页先按照活页本编号、再按照页码从小到大排序
t=i
For j=i+1 To sum
If Then t=j
Next j
tmp=a(i):a(i)=a(t):a(t)=tmp
tmp=b(i):b(i)=b(t):b(t)=tmp
Next i
c(1)=a(1) '对于每个奇数位i,c(i)与c(i+1)分别存储连续页码的起始编号和结尾编号
d(1)=b(1)
s=1
t=a(1)
For i=2 To sum
If b(i)=b(i-1)And t+1=a(i)Then
Else
c(s*2)=t
s=s+1
=a(i)
d(s)=b(i)
t=a(i)
End If
Next i
c(s*2)=t
List2.AddItem "第1本书:"
List2.AddItem Str(c(1))+"-"+Str(c(2))
For i=2 To s
If d(i)<>d(i-1)Then List2.AddItem"第"+Str(d(i))+"本书:"
List2.AddItem Str(c(2*i-1))+"-"+Str(c(2*i))
Next i
End Sub
选手成绩的计算规则是:计算评分最高前k个的平均分avg1,剩余评分的平均分avg2,找到avg1与avg2差值最小,则avg1与avg2的平均数为该选手得分。例如,某选手的评委评分为6,5,3,1,则各位次评分为:
k |
1 |
2 |
3 |
avg1 |
6 |
5.5 |
4.67 |
avg2 |
3 |
2 |
1 |
avg1-avg2 |
3 |
3.5 |
3.67 |
由表格可知,差值最小为3,因此该选手的评分为(6+3)/2=4.5。按上述要求,编写VB程序,功能如下:在列表框List1中显示各选手的评委评分,单击“计算”按钮Command1,在列表框List2中依次按照得分从高到低显示每位选手成绩。程序运行界面如图所示。请回答下列问题:
Const n=8
Const m=12
Dim a(n*m)As Double,b(m)As Integer
Dim f(n)As Double,num(n)As Integer,sum As Double
Private Sub Form_Load()
'读取n个人每个评委的评分,按照选手编号从小到大依次存入数组a,并显示在List1中
'a(1)到a(m)存储第1个选手得到的m个评委的评分
'a(m+1)到a(2*m)存储第2个选手得到的m个评委的评分
'以此类推,代码略
End Sub
Private Sub Command1_Click()
Dim i As Integer,j As Integer,x As Integer,k As Integer
Dim s As Double,avg1AsDouble,avg2AsDouble
Dim ans_v As Double,ans_c As Double
For i=1 To n
sum=0
For j=1 To m
sum=sum+a((i-1)*m+j)
b(j)=0
Next j
s=0
ans_v=-1:ans_c=0
For j=1 To m-1
x=find(i) '找到第i组中m个数中第j大数位置x
avg1=s/j
avg2=(sum-s)/(m-j)
If ans_v=-1 Or avg1-avg2<ans_c Then
ans_v=(avg1+avg2)/2
ans_c=avg1-avg2
End If
Next j
Do While k>=1 And ans_v>f(k)
f(k+1)=f(k)
num(k+1)=num(k)
k=k-1
Loop
f(k+1)=ans_v
num(k+1)=i
Next i
'将结果显示在List2中,代码略
End Sub
Function find(t As Integer)As Integer
Dim i As Integer
find=0
For i=(t-1)*m+1 To t*m
IfThen
If find=0 Or a(find)<a(i)Then find=i
End If
Next i
b(find-(t-1)*m)=1
End Function