Do While i <= n
x = Int(Rnd() * 9) + 1 If x Mod 2 = 1 Then
a(i) = x Else
a(n) = x n = n - 1
End If
i = i + 1 Loop
数组元素的初值均为 0,执行该程序段后,在下列选项中 a(1)至 a(5)各元素值不可能的是( )
Do While i <= 5
If i = 1 Or a(i - 1) <= a(i) Then i = i + 1
Else
t = a(i): a(i) = a(i - 1): a(i - 1) = t i = i - 1
End If Loop
数组元素a(0)到a(8)的初始值依次为“0,4,7,3,5,1,8,6,2”。执行该程序段后,数组元素a(1)到a(8)的值分别是
i = 1: j = 63: n = 0
Do While i <= j
m = (i + j) \ 2
If key = a(m) Then Exit Do
ElseIf 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,则下列表达式成立的是( )
图 a
图 b
图 a
图b
实现上述功能的VB代码如下:
Dim a(1 To 100) As Integer Private Sub Command1_Click()
Dim i As Integer, s As Integer, smax As Integer ‘用于随机生成数据,并将阵列按规则在列表框中输出,该部分功能的代码略。
smax = 0
For i = 1 To 100
If a(i) = 0 Then s = search(i) If s > smax Then smax = s
Next i
Label1.Caption = "最大面积的矩形,占" + Str(smax) + "个单位。" End Sub
Function search(i As Integer) As Integer
Dim x As Integer, x1 As Integer, xend As Integer Dim y As Integer, y1 As Integer
Dim s As Integer
x = (i - 1) Mod 10 + 1 '起始列号 y = (i - 1) \ 10 + 1 '起始行号 x1 = x
y1 = y xend = 10
search = 0
Do While y1 <= 10
If a((y1 - 1) * 10 + x) = 1 Then Exit Do '判断 x1 = x
Do While x1 <= xend
If a((y1 - 1) * 10 + x1) = 1 Then
x1 = x1 – 1 '改错
Else
x1 = x1 + 1
End If Loop
y1 = y1 + 1
s = (x1 - x) * ( ) '填空 If s > search Then search = s
Loop
End Function
请回答下列问题:
实现上述功能的VB代码如下:
Private Sub Command1_Click() Dim a(0 To 4) As String Dim b(0 To 4) As Integer
Dim s As String, r As String
Dim i As Integer, j As Integer, k As Integer, c As Integer, n As Integer
List1.Clear
s = Text1.Text : n = Len(s)
If Then '选填 Label1.Caption = "数据输入有误!"
Exit Sub '退出 End If
For i = 0 To n - 1
a(i) = Mid(s, i + 1, 1) b(i) = 0
Next i c = 0
For i = 1 To n ^ n r = ""
For j = 0 To n - 1
Next j
c = c + 1 List1.AddItem r k = 0
b(k) = b(k) + 1
Do While b(k) = n And k < 4 b(k) = 0
b(k) = b(k) + 1 Loop
Next i
Label1.Caption = "构造字符串的方法共计" + Str(c) + "种。" End Sub
Function test(s As String) As Boolean ‘用于判别是否存在重复的字符,代码略
‘若无重复,则返回True,否则返回False
End Function
请回答下列问题:
② ③