s = "ERROR:Divisor must not be zero!"
flag = False : m = 0
For i = 1 To Len(s)
ch = Mid(s, i, 1)
If ch >= "a" And ch <= "z" Then
If Not flag Then
m = m + 1 : flag = True
End If
Else
flag = False
End If
Next i
Text1.Text=Str(m)
t = "": i = 1 : j = 9 : f = False
Do While i <= j And Not f
m = (i + j) \ 2
t = t + Str(m)
If a(m) = key Then
t =t +“#”
f = True
ElseIf a(m) > key Then
i = m + 1
t = t + "→"
Else
j = m - 1
t = t + "←"
End If
Loop
数组元素 a(1)到 a(9)的值依次为“68、56、52、36、32、28、26、22、20”,执行该程序段,t的值可能是( )
综上所述:原文为Jim is at room 4!,加密后输出密文为:NMQ MW EX VSSQ 2!
Private Sub Cmd1_Click()
Dim str1 As String, str2 As String, ch As String
Dim i As Integer, j As Integer, n As Integer
str1 = Text1.Text
str2 = ""
n = Len(Text1.Text)
For i = 1 To n
ch = Mid(str1, i, 1)
If Then
ch = Chr((Asc(ch) - 32))
End If
If ch >= "A" And ch <= "Z" Then
ch = Chr((Asc(ch) - Asc("A") + 4) Mod 26 + Asc("A"))
ElseIf ch >= "0" And ch <= "9" Then
ch =
End If
Next i
Text2.Text = str2
End Sub
'顺序查找代码,查找次数用变量p表示
For i = 1 To 10
If a(i) = Key Then
p = i
End If
Next i
'二分查找代码,查找次数用变量q表示
i=1 :j=10 :find=Fasle
Do While i<=j And find=fasle
x =(i+j)\2
q = q+1
If a(x)=Key Then find=True
If a(x)>Key Then j=x-1
If a(x)<Key Then i=x+1
Loop
若变量key的值为13,程序运行后,则变量p和q的值分别是( )
i=l:j=9:n=0
key=Val(Text1,Text)
Do While i<=j
n=n+1
m=Fix((i+j) / 2)
If key=d(m) Then Exit Do ‘Exit Do表示退出循环
If key<d(m) Then j=m-1 Else i=m+1
Loop
数组元素d(1)到d(9)的值依次为“7,12,18,25,39,58,61,72,86”。若该程序段运行结束后,n的值为2,则key的值是( )
Dim a(1 To 6)As Integer
Dim i As Integer,j As Integer,Key As Integer,m As Integer
a(1)=11:a(2)=22:a(3)=33: a(4)=44:a(5)=55:a(6)=66
i=1:j=6:p=0:Key=23
Do While i<=j
p=p+1
m=(i+j)\2
If j Mod 2=0 Then m=m+1
If a(m)=Key Then Exit Do
If Key<a(m) Then j=m-1
Else i=m+1
Loop
请回答下列问题:
Const maxn=10
Dim a(1 To maxn) As Integer
Private Sub Form_Load()
‘maxn个数据存储在数组a中,并在列表框List1中显示
‘代码略
End Sub
Private Sub Command1_Click()
Dim i As Integer, n As Integer ‘n用于存储当前査找的数组长度
Dim j As Integer, key As Integer ‘key用于存储本次查找关键字的数据位置
key=1: n=maxn
Do While key <=n
i=n
Do While a(i) <> a(key)
Loop
If i=key Then ‘未找到,重新下一査找关键字
key=key+1
Else ‘找到重复数据,删除
For j=i To n-1
Next j
n=n-1
End If
Loop
For i=1 To n
List2.AddItem Str(a(i))
Next i
Label1.Caption=“共删除数据”++“个”
End Sub
key = Val(Text1.Text)
i = 1: j = n * 2 : flag = False
Do While i + 1 <= j And Not flag
m = (i + j) \ 2
If ① Then m=m-1
If a(m) = key Or a(m + 1) = key Then
flag = True
ElseIf a(m) > key Then
②
Else
③
End If
Loop
If a(i) = key Or a(j) = key Then flag = True
If flag Then Label1.Caption = "yes" Else Label1.Caption = "no"
划线处的代码正确的是( )
Key=Int(Rnd*10)+1
If Key>5 Then Key=Key+5
i=1:j=10:n=0
Do While i<=j
m=(i+j)\2
If Key<=d(m) Then
j=m-1:n=n-1
Else
i=m+1:n=n+1
End If
Loop
Label 1.Caption=Str(n)
若数组元素d(1)到d(10)的值依次为“1,3,4,5,7,8,11,13,15,18”,执行该程序段后,则在标签Label 1中显示的结果不可能为( )
i=1:j=10
Key=Val(Text1.Text)
Do While i<=j
m=(i+j)\2
If a(m)=Key Then Exit Do 'Exit Do表示退出循环
If Key Mod2=1And a(m)Mod 2= 0 Then
ElseIf Key Mod 2= 0 And a(m)Mod 2= 1 Then
Else
End If
Loop
If i >j Then s="没有找到!"Else s="位置:"+Str(m)
Text2.Text=s
上述程序中方框处可选语句为:
①i=m+1
②j=m-1
③If Key<a(m)Then j=m-l Else i=m+1
则(1)(2)(3)处语句依次是( )
n = 0 : i = 1 : j = 8
Key = Val(Text1.Text)
Do While i <= j
m = (i + j) \ 2
If Key = d(m) Then Exit Do 'Exit Do表示退出循环
If Key > d(m) Then
j = m - 1 : n = n - 1
Else
i = m + 1 : n = n + 1
End If
Loop
Label1.Caption = Str(n)
当输入不同的Key值,运行该程序段后,在标签Label1中显示的不同结果共有( )
⑴11 99 5 17 2 39
⑵30 52 63 71 78 81
⑶67 62 68 6 15 15
⑷85 78 59 53 19 18
i=1:j=7: key=72
Do while i<=j
m= Fix((i+5)/2)
1f key= a(m) Then Exit Do
If key<a(m)Then j=m-1 Else i=m+1
Loop
数组元素a(1)到a(7)的值依次为“12,23,48, 65,72,81,97”执行该程序段至结束时,共查找的次数是( )
Dim n As Integer, i As Integer, left As Integer, right As Integer, m As Integer
Dim a(1 To 10) As String, t As String, key As String n = 6
a(1) = "35": a(2) = "20": a(3) = "18": a(4) = "8": a(5) = "274": a(6) = "47" For i = 1 To n - 1
For j = n To i + 1 Step -1
If a(i) < a(j) Then
t = a(i): a(i) = a(j): a(j) = t
End If
Next j
Next i
key = Text1.Text
left = 1: right = n
Do While left <= right
m = (left + right) \ 2
If a(m) = key Then Exit Do
If a(m) < key Then right = m - 1 Else left = m + 1
Loop
若在文本框 Text1 中输入“212”,则程序运行结束后,m 的值为( )
i=1: j=63: n=0
Do While i<=j
M=(i+j)\2
If Key=a(m) Then
Exit Do
Elself Key<a(m) Then
J=m-1:n=n-1
Else
I=m+1:n=n+1
End if
Loop
数组元素a(1)到a(63)存放着递增的数据。若执行该程序段后n的值为6,则下列表达式成立的是( )
i = 1:j = 8:s = ""
key = Text1. Text
Do While i <= j
m = (i +j)\2
If key = a(m) Then
s = s+ "M"
Exit Do
ElseIf key <a(m) Then
j = m -1:s = s+ "L"
Else
i = m+1:s = s + "R"
End If
Loop
Text1. Text = s
数组元素a(1)到a(8)的值依次为“4,22,27,32,35,44,56,59”,该程序段执行后,文本框Text1中显示的内容不可能是( )
解决此问题的程序代码如下:
Const n As Integer= 10 'n为学生数
Dim a(1 To n) As String '数组a用于存储学生的编号
Dim b(1 To n)As Integer数组b用于存储学生的身高
Private Sub Command1_ Click()
'此过程用于在列表框List2中显示给定身高的所有学生的编号,代码略。
End Sub
以下函数用于查找给定身高的学生的相关信息
Private Function FindEx(k As Integer) As Integer
Dim f As Boolean, i As Integer, j As Integer, m As Integer
i=1 : j=n
f= False
Do While (i <=j) And Not (f)
m=Fix((i+j) / 2)
If k=b(m) Then
f= ①
Else
If k<b(m) Then
j=m-1
Else
②
End If
End If
Loop
If f Then FindEx=m Else FindEx=0
'找到返回m,否则返回0
End Function
Private Sub Form_ Load()
'此过程用于对数组a和数组b进行赋值,并把数据显示在列表框List1中。代码略
End Sub
①②