修改时间:2021-05-20 浏览次数:205 类型:开学考试
s = Text1.Text n = Len(s)
s1 = s
i = 1
Do While i <= Len(s)
i = i + 1
Loop
Text2.Text = s1
上述程序中方框(1)处的可选语句有:
①ch = Mid(s, i, 1)
②ch = Mid(s, n - i + 1, 1)
③s1 = s1 + ch
④s1 = ch + s1
则正确的语句为 ( )
n = 8
L = 1: R = n
For i = 1 To n - 1
If i Mod 2 = 1 Then
pos = L: L = L + 1
Else
pos = R: R = R - 1
End If
k = pos
For j = L To R
If a(j) < a(k) Then k = j
Next j
If pos <> k Then
t = a(pos): a(pos) = a(k): a(k) = t
End If
Next i
已知a数组的各元素值分别为12,18,23,25,9,47,29,36,则运行程序段后,a数组各元素的值变为 ( )
'数组元素f(1)到f(9)赋初值为0,代码略
Key = Val(Text1.Text)
i = 1: j = 9: flag = False
Do While i <= j And flag = False
m = (i + j) \ 2
f(m) = 1
k = k + 1
If a(m) = Key Then
flag = True
ElseIf a(m) > Key Then
j = m - 1
Else
i = m + 1
End If
Loop
整型数组元素a(1)到a(9)为升序序列,在文本框Text1中输入待查找数,执行该程序段后,f(1)到f(9)各元素值为“0,0,0,0,1,1,1,0,0”,则下列选项中描述正确的是 ( )
请回答下列问题:
(提示:2019年比2018年增幅(%)数据的计算公式为:是通过公式(2019年相关数据-2018年相关数据)/2018年相关数据×100计算得到)
①以“地域”为主要关键字降序,以“出生率”为次要关键字进行升序排序
②以“出生率”为主要关键字升序,以“地域”为次要关键字进行降序排序
③按“地域”进行筛选,选择的值为“浙西南”
④按“出生率”进行筛选,选择“10个最大的值”并显示最小的1项
⑴将数组a中的n个元素依次分割出若干个数据块,每个数据块有2m个元素,分割时,按尽可能大的数据块进行分割。
⑵对每个分割出的数据块进行求和,将和依次存储在数组b中。
例如:n=13,可将a(1)~a(13)依次分割成3个数据块,元素的个数分别为8、4、1。将3个数据块的和依次存储在b(1)、b(2)、b(3)中。
小明依据上述描述设计了如下VB程序,运行界面如图所示。请回答下列问题:
Const n = 13
Dim a(1 To n) As Integer Dim b(1 To n) As Integer Private Sub Command1_Click()
Dim start As Integer ‘当前未分割数据的第1个元素下标
Dim i As Integer, k As Integer, pb As Integer, left As Integer, m As Integer
'读取n个数据,依次存储到a(1)、a(2)、……a(n)中,并对数组b赋初值为 0,代码略
start = 1: left = n: m = 0
Do While 2 ^ m <= left ‘寻找第1个数据块
①
Loop
m = m - 1
pb = 1
Do While left > 0
For i = start To start + 2 ^ m - 1
②
Next i
List1.AddItem Str(2^m) + " " + Str(b(pb)) pb = pb + 1
‘改错
left = left - 2 ^ m
Do While left < 2 ^ m
m = m - 1
Loop
Loop
End Sub
① ②
程序功能如下:加载窗体,程序将相关数据存储到数组a、数组b,并显示在列表框List1中,然后单击“统计”按钮Command1,在列表框List2中显示统计结果。数组b各元素含义如图a所示。程序运行界面如图b所示。
请回答下列问题:
Dim n As Integer, m As Integer
Dim a(1 To 1000) As String
Dim b(1 To 3000) As Single
Private Sub Form_Load()
'将参赛人数存入变量n,比赛轮数存入变量m中
'将选手序号存储到数组a中、打靶成绩存储到数组b中,并显示在列表框List1中,代码略
End Sub
Private Sub Command1_Click()
Dim i As Integer, j As Integer, t As Integer
Dim max As Single, s1 As String, s2 As Single
Dim sum(1 To n) As Single
'对数组 sum 中各元素赋初值 0,代码略
For i = 1 To m
t =
For j = 1 To n
max = fm(b(t + (j - 1) * 3 + 1), b(t + (j - 1) * 3 + 2))
max =
sum(j) = sum(j) + max
Next j
Next i
For i = 2 To n '按总分对参赛人员进行排序
j = i - 1
s1 = a(i)
s2 = sum(i)
Do While
a(j + 1) = a(j)
sum(j + 1) = sum(j)
j = j - 1
Loop
a(j + 1) = s1
sum(j + 1) = s2
Next i
For i = 1 To n
List2.AddItem "第" + Str(i) + "名" + a(i) + " " + Str(sum(i))
Next i
End Sub
Function fm(x As Single, y As Single) As Single
'返回 x、y 中的较大值,代码略
End Function
试题篮