修改时间:2021-05-20 浏览次数:199 类型:月考试卷
Private Sub Command1_Click()
Dim a(1 To 6) As Integer
Dim d(1 To 6) As Integer
a(1) = 28: a(2) = 21: a(3) = 30: a(4) = 11: a(5) = 12: a(6) = 29
Const n = 6
Max = 0
For i = 1 To n
d(i) = 0
For j = 1 To i - 1
If a(j) < a(i) Then d(i) = d(i) + 1
Next j
If d(i) > Max Then Max = d(i)
Next i
End Sub
执行完以上程序后,Max的值为( )
For i = 1 To 8
a(i) = (Int(Rnd * 10) + 1) * (i Mod 2 + 1)
Next i
k = 1
For i = 1 To 3
For j = 1 To 8 - 2 * i
If k * a(j) < k * a(j + 2) Then
t = a(j): a(j) = a(j + 2): a(j + 2) = t
End If
k = -k
Next j
Next i
执行该程序后,a(1)~a(8)可能的值为( )
Key=Val(Text1.Text) i=1:j=10 flag=False
Do While i<=j And Not flag Lmid= ⑴
Rmid=j-(j-i)\3
If Key=a(Lmid) Or Key=a(Rmid) Then Flag=True
Elseif ⑵ Then
i=Lmid+1
j=Rmid-1
Elseif Key<a(Lmid) Then
j=Lmid-1
Else
i=Rmid+1
End if
Loop
If Flag And Key=a(Lmid) Then
List1.AddItem Str(Lmid)
ElseIf Flag Then
List1.AddItem Str(Rmid)
Else
List1.AddItem ⑶ EndIf
上述程序中方框处可选语句为:
①(j-i)\3+i ②(i+j)\3+1 ③Key<a(Lmid) And Key>a(Rmid) ④Key>a(Lmid) And Key<a(Rmid)
⑤str(i)+str(j) ⑥Str(j)+Str(i)
则(1)(2)(3)处的语句依次为( )
|
请回答下列问题:
如上图所示,通过K3单元格中的公式,得出程小萍的业绩超过95%的销售额,对K4:K46进行自动填充,K46单元格中的显示结果是(单选,填字母: A . # VALUE! / B .26%/ C . #DIV/0! / D . 100%)。
请回答下列问题:
⑴用数组依次存储每个非降序数列中最大的元素(查找过程中的最大值),初始时b(1)为数组a第1个元素。
⑵加入方法:将a(i)与数组b中的每个元素依次逐个比较:
若a(i)不比b(j)小就用a(i)替换b(j)中的值;将a(i)添加到第j个非降序数列中,并连接到c数组的c(j)中。
若a(i)比b(j)都小,则在数组b最后添加新的元素值为a(i),即将a(i)添加到第j+1个下降数列中,并连接到c数组的c(j+1)中。
⑶若数组a各元素的值为:12,36,16,36,27,18时,则3个非降序数列分别为:“12,36,36”,“16,27”,“18”。
程序运行界面如下图所示:
小明依据上述描述设计了如下VB程序。请回答下列问题:
Const m=15
Dim a(1 To m) As Integer Private Sub Form_Load()
‘读取m个数据,依次存储到 a(1)、a(2)、……a(m)中,代码略End Sub
Private Sub Command1_Click()
Dim b(1 To m) As Integer '存储数列最大的值Dim c(1 To m) As String ‘存储非降序数列Dim i As Integer
Dim bottom As Integer Dim j As Integer
Dim bn As Integer ‘存储非降序数列的个数List1.clear
b(1) = a(1)
①
c(1) = Str(a(1))
For i = 2 To m
For j = 1 To bn
If ② Then
b(j) = a(i)
Exit For
End If
Next j
If j > bn Then
bn = bn + 1
③
c(b(n)) = Str(a(i))
End If
Next i
For i = 1 To bn
List1.AddItem c(i)
Next i
Text2.Text = "数列中共有" + Str(bn) + "个非降序序列"
End Sub
① ② ③
李同学设计了一个用来求两座岛屿之间相连所需桥的数量的VB程序,点击“生成矩阵”按钮Command1,随机产生一个关系矩阵,并在列表框List1中显示。在文本框Text1和Text2中输入岛屿的编号(1~9),点击“求解”按钮Command2,在Labell中输出两座岛屿之间相连所需桥的数量。VB程序运行界面如图所示。
对无桥相连的两座岛屿p1,p2之间相连的算法思想如下:
①p1岛屿所在行开始,将与其相连的岛屿依次添加到数组b中。
②若数组b中未出现岛屿p2,则依次查找与其相连岛屿的所在行,将新出现的相连的岛屿添加到数组b中。
③在查找过程中同时记录查找步数。
数组b内全部搜索完毕,若p2还是未出现,则两座岛屿之间无法相连,反之输出桥的数量。请回答以下问题:
Const n = 9 ‘岛屿的数量
Dim a(1 To n * n) As Integer
Private Sub Command1_Click()
Dim s As String List1.Clear
For i = 1 To n
For j = i To n
If j = i Then
a((i - 1) * n + j) = 0 ‘对角线为0
Else
a((i - 1) * n + j) = Int(Rnd * 2)
① ‘矩阵对称
End If
Next j Next i
For i = 1 To n
s = ""
For j = 1 To n
s = s + Str(a((i - 1) * n + j))
Next j
List1.AddItem s Next i
End Sub
Private Sub Command2_Click()
Dim b(1 To n) As Integer
Dim qiao(1 To n) As Integer ‘记录相连岛屿之间桥的数量
Dim find(1 To n) As Boolean ‘记录某岛屿是否被添加到数组b中
Dim p1 As Integer, p2 As Integer, cur As Integer, k As Integer, q As Integer
p1 = Val(Text1.Text)
p2 = Val(Text2.Text)
cur = p1: k = 1: q = 0
find(cur) = True
Do While find(p2) = False
For i = 1 To n
If a((cur - 1) * n + i) = 1 And find(i) = False Then
b(k) = i: k = k + 1
find(i) = True
②
End If
Next i
q = q + 1
If q = k Then Exit Do Else ③
Loop
If find(p2) = True Then
Label1.Caption = "需要经过" + Str(qiao(p2)) + "座桥"
Else
Label1.Caption = "无桥相连"
End If
End Sub
① ② ③
试题篮