题型:单选题 题类:常考题 难易度:普通
浙江省2020届高三上学期信息技术五校联考试卷
Key = Int(Rnd * 49) * 2 + 1
s = 0: i = 1: j = 10
Do While i <= j
m = (i + j) \ 2
If Key = a(m) Then Exit Do If Key < a(m) Then
j = m - 1: s = 2 * s
Else
i = m + 1: s = 2 * s + 1
End If Loop
数组a(1)到a(10)的值依次为“2,6,7,15,20,24,27,43,52,63”,执行该程序段后,s的值不可能为( )
a(1) |
a(2) |
a(3) |
…… |
a(n —2) |
a(n—1) |
a(n) |
3 |
25 |
38 |
…… |
55 |
31 |
12 |
依据对分查找思想,设计一个在数组a中查找数据key的程序。实现该功能的VB程序如下,但加框处代码有错,请改正。
Private Sub Command1_Click()
Const n = 6
Dim a(1 To n)As Integer,flag As Boolean
Dim i As Integer,j As Integer,m As Integer,key As Integer
'读取一组正整数,按上述规则存入数组a中,代码略。
key = VaKText1. Text)
i = 1
j = (n + 1) \ 2
flag = False
Do While And Not flag ‘①
m = (i + j) \ 2
If key = a(m) Then
flag = True
ElseIf key< a(m) Then
j = m - 1
Else
i = m + 1
End If
Loop
If Not flag And j > 0 Then
m = ‘②
If key = a(m) Then flag = True
End If
If flag Then
Text2. Text = Str(m)
Else
Text2. Text = "找不到"
End If
End Sub
①{#blank#}1{#/blank#} ②{#blank#}2{#/blank#}
试题篮