n=0
Key = Val(Text1. Text)
i = 1 : j= 10 : f= False
Do While i<= j And f = False
n=n+1
m=(i+j+1)\2
If a(m)=Key Then f=True
If a(m)>Key Then j=m-1 Else i=m+1
Loop
Text1. Text = Str(n)
数组元素a(1)到a(10)的值依次为“14,17,30,42,55,69,80,83,88,90”,执行该程序段,输入key的值为a(1)到a(10)中的某一个值,文本框Text2中显示的值为3,则key位可能是( )
Dim i As Integer,c As String,s As String,t As Integer
Dim s2 As String,pwd As String
s=Text1.Text:pwd="71zhYEAR":s2="":t=0
For i = 1 To Len(s)
c=Mid(s,i,1)
If c>="0" And c<="9"Then
t=t*10+Val(c)
Else
s2=s2+Mid(pwd,t Mod 8+1,1)
End If
Next i
Text2.Text=s2
运行该程序段,在文本框Text1中输入“20B13A8”,文本框Text2输出的是( )
For i=1 To 2
For j=5 To i+1 Step-1
If a(j)<a(j-1) Then
t=a(j) : a(j)=a(j-1) : a(j- 1)=t
End If
Next j
Next i
数组元素a(1)到a(5)的值依次为“95,88,66,80,75”,经过该程序段“加工”后,数组元素a(1)到a(5)的值依次为( )
For i=1 To 6
If i Mod 2<>0 Then
If a(i) Mod 10>5 Then
a(i)=a(i) \ 10
Else
a(i)=a(i) Mod 10
End If
Else
a(i)=a(i- 1)+1
End If
Next i
程序运行后a(1)到a(6)的值分别是2,3,4,5,0,1,则a(1)到a(6)各元素的初始值可能是( )
实现上述功能的VB代码如下,请回答下列问题:
Const n= 10
Dim a(1 To n) As Integer
Private Sub Form_ load( )
'数组初始化,生成1~20之间的随机整数并赋值给数组a,代码略
End Sub
Private Sub Cmd1_Click()
Dim i As Integer, j As Integer, t As Integer
Dim bottom As Integer
bottom= n
For i=1 To bottom-1
For j= bottom To i+1 Step -1
If Then '①改错
t=a(j) : a(j)=a(i) : a(i)=t
ElselIf a(j)=a(i) Then
'②填空
bottom= bottom- 1
End If
Next j
Next i
Text2. Text=" "
For i=1 To bottom
Text2. Text= Text2. Text+Str(a(i))
Next i
End Sub
Dim a(1 To 10) As Integer, b(1 To 10) As Integer
Private Sub Command1_Click( )
Dim i As Integer, time As Integer, k As Integer
Dim c(1 To 20) As Integer, nc As Integer
c(1)=a(1) :nc= 1
For i=1 To 9 '删除起点重复数据后添加到数组c
If a(i)<>a(i+1) Then
nc=nc+1
End If
Next i
For i=1 To 10 '删除终点重复数据后添加到数组c
k= nc
Do While b(i) < c(k)
k=k- 1
Loop
If Then '非重复 数据(新停靠楼层)添加到数组c
For j=nc To k+1 Step -1
c(j+1)=c(j)
Next j
nc=nc+1
c(j+1)=b(i)
End If
Next i
time=(c(nc)-c(1)) *3+nc*8
Text1. Text="总时间--"+Str( time)+ "秒"
End Sub
Private Sub Form_ Load( )
'生成10批入的起止楼层,分别给数组a和b,并在列表框list1输出,代码略。
For i=1 To 9
For j=10 To i+1 Step -1
If a(j)<a(j-1)Or Then
t=a(j) : a(j)=a(j-1) : a(j-1)=t
t=b(j) : b(j)=b(j - 1) : b(j-1)=t
End If
Next j
Next i
For i=1 To 10
List2. AddItem Str(a(i))+Str(b(i))
Next i
End Sub