(加试题)以下一段程序其功能是对数组a(下标范围为1 to n)中的数据进行升序排序,划线处应填入的正确语句是( )
For i =
For j = 2 To i
If a(j) > a(j - 1) Then
k = a(j): a(j) = a(j -1): a(j -1) = k
End If
Next j
Next i
For i =
For j = 2 To i
If a(j) > a(j - 1) Then
k = a(j): a(j) = a(j -1): a(j -1) = k
End If
Next j
Next i
A.n to 2 Step -1 | B.2 to n | C.n-1 to 1 Step -1 | D.1 to n -1 |
将6名选手的歌唱比赛成绩存放在数组a中,如下表所示:

若按升序排列,采用冒泡排序算法自右向左进行比较和交换,那么完成前二轮的数据处理,比较的总次数为

若按升序排列,采用冒泡排序算法自右向左进行比较和交换,那么完成前二轮的数据处理,比较的总次数为
A.10 |
B.4 |
C.9 |
D.5 |
(加试题)小李基于冒泡排序算法编写了一个VB程序,功能如下:在文本框Text1 中显示排序前的数据,单击“排序”按钮Command1,在文本框Text2 中显示剔除重复数据后的升序排序结果。程序运行界面如下图所示。

实现上述功能的VB程序如下,但加框处代码有错,请改正。
Const n = 10
Dim a(1 To n) As Integer
Private Sub Command1_Click()
Dim i As Integer, j As Integer, t As Integer, bottom As Integer
'获取排序前数据依次存储在数组a 中,并在文本框Text1 中显示。代码略
bottom = n : i = 1
Do While i <= bottom - 1
t = a(j): a(j) = a(j - 1): a(j - 1) = t
ElseIf a(j) = a(j - 1) Then ' 相邻两个数据相等,进行剔除处理
a(bottom)=a(j)
bottom = bottom - 1
End If
Text2.Text = " "
For i = 1 To bottom
End Sub

实现上述功能的VB程序如下,但加框处代码有错,请改正。
Const n = 10
Dim a(1 To n) As Integer
Private Sub Command1_Click()
Dim i As Integer, j As Integer, t As Integer, bottom As Integer
'获取排序前数据依次存储在数组a 中,并在文本框Text1 中显示。代码略
bottom = n : i = 1
Do While i <= bottom - 1
For j = bottom To i + 1 Step -1
If a(j) < a(i) Thent = a(j): a(j) = a(j - 1): a(j - 1) = t
ElseIf a(j) = a(j - 1) Then ' 相邻两个数据相等,进行剔除处理
a(bottom)=a(j)
bottom = bottom - 1
End If
Next j
i = i + 1
LoopText2.Text = " "
For i = 1 To bottom
Text2.Text = Text2.Text + Str(a(i))
Next iEnd Sub
(加试题)某排序算法的VB程序段如下:
n = 10
Text1.Text = ""
For i = 1 To 5
For j = n To i + 1 Step -1
If a(j) < a(i) Then
temp = a(j): a(j) = a(i): a(i) = temp
End If
Next j
Next i
For i = 1 To 10
Text1.Text = Text1.Text + Str(a(i))
Next i
数组元素a(1)到a(10)的值依次为“965,155,195,444,106,734,172,983,898,360”,执行该程序段,文本框Text1中显示的是
n = 10
Text1.Text = ""
For i = 1 To 5
For j = n To i + 1 Step -1
If a(j) < a(i) Then
temp = a(j): a(j) = a(i): a(i) = temp
End If
Next j
Next i
For i = 1 To 10
Text1.Text = Text1.Text + Str(a(i))
Next i
数组元素a(1)到a(10)的值依次为“965,155,195,444,106,734,172,983,898,360”,执行该程序段,文本框Text1中显示的是
A.106 155 172 195 360 444 734 898 965 983 |
B.106 155 172 195 360 734 444 983 898 965 |
C.983 965 898 734 444 360 172 195 155 106 |
D.106 155 172 195 360 965 444 734 898 983 |
(加试题)有一组正整数,基于冒泡排序对其中的数进行升序排序。排序后奇数在前,偶数在后。排序示例如下:
实现上述功能的VB程序如下,但加框处代码有误,请改正。
Const n = 10
Dim d(1 To n) As Integer
Private Sub Command1_Click()
Dim i As Integer, j As Integer, t As Integer
'读取一组正整数,存储在数组d中,代码略
i = 1
Do While i <= n - 1
For j = n To i + 1 Step -1
If d(j) Mod 2 = d(j - 1) Mod 2 Then
If d(j) > d(i) Then '(1)________
t = d(j): d(j) = d(j - 1): d(j - 1) = t
End If
Else '(2)________
t = d(j): d(j) = d(j - 1): d(j - 1) = t
End If
Next j
i = i + 1
Loop
'依次输出排序后的数据,代码略
End Sub
排序前 | 78 | 30 | 64 | 39 | 49 | 4 | 8 | 32 | 18 | 32 |
排序后 | 39 | 49 | 83 | 4 | 8 | 18 | 30 | 32 | 64 | 78 |
实现上述功能的VB程序如下,但加框处代码有误,请改正。
Const n = 10
Dim d(1 To n) As Integer
Private Sub Command1_Click()
Dim i As Integer, j As Integer, t As Integer
'读取一组正整数,存储在数组d中,代码略
i = 1
Do While i <= n - 1
For j = n To i + 1 Step -1
If d(j) Mod 2 = d(j - 1) Mod 2 Then
If d(j) > d(i) Then '(1)________
t = d(j): d(j) = d(j - 1): d(j - 1) = t
End If
Else '(2)________
t = d(j): d(j) = d(j - 1): d(j - 1) = t
End If
Next j
i = i + 1
Loop
'依次输出排序后的数据,代码略
End Sub
有如下程序段:
Const n = 6
Dim a(1 To n) As Integer
Dim i As Integer, j As Integer, t As Integer
Do While True
For i=1 to n-1
If a(i)>a(i+1) then Exit For
Next i
If i < n Then
For i = 1 To n
j = Int(Rnd * 6) + 1
t = a(j): a(j) = a(i): a(i) = t
Next i
Else
Exit Do
End If
Loop
数组中a(1)到a(6)的值依次为“56,34,48,87,65,96”,经上述程序段执行后a(1)到a(6)的值依次为( )
Const n = 6
Dim a(1 To n) As Integer
Dim i As Integer, j As Integer, t As Integer
Do While True
For i=1 to n-1
If a(i)>a(i+1) then Exit For
Next i
If i < n Then
For i = 1 To n
j = Int(Rnd * 6) + 1
t = a(j): a(j) = a(i): a(i) = t
Next i
Else
Exit Do
End If
Loop
数组中a(1)到a(6)的值依次为“56,34,48,87,65,96”,经上述程序段执行后a(1)到a(6)的值依次为( )
A.96 87 65 56 48 34 |
B.34 48 56 65 87 96 |
C.选项A和B都有可能 |
D.选项A和B都不可能 |
(加试题)某密码的破译步骤如下:
(1)找出文章(以“.”结束)中所有用英文表示的数字(均为小写,数字范围1≤n≤20),单词与数字对应如下:

(2)将这些数字平方后除以100取余,得到两位数如00,04,21,96。
(3)把这些两位数按升序排成一行,组成一个最小的新数,如果新数开头为0,就去除。
(4)步骤(3)找出的最小数即为密码。
小明按照上述方法,设计了一个解密的VB程序,功能如下:单击“解密”按钮Commandl,程序依次将文本框Textl中以空格分隔的每个英文单词取出,若单词属于数字单词,则按解密步骤进行处理,最后在文本框Text2中输出解密结果。
程序运行效果如图所示,请回答下列问题:

(1)若文章内容为“tom bought two apples and five oranges, which cost ten dollars altogether.”,则破译后的密码应为_____________。
(2)请在划线处填入合适的代码。
Dim a(1 To 20) As String
Private Sub Form_Load()
a(1) = "one": a(2) = "two"
'……将所有数字单词按顺序存入数组a中,代码略
End Sub
Private Sub Command1_Click()
Dim s As String, tmp As String
Dim c as Integer,i As Integer, j As Integer, k As Integer, t As String, ch As As String,code As Long
Dim b(1 To 100) As String 'b数组存放数字单词处理后得到的两位数
s = Text1.Text
c = 0: i = 1: flag = True:t = ""
Do While i <= Len(s)
ch = Mid(s, i, 1)
If ch >= "a" And ch <= "z" Then
t = t + ch
flag = False
ElseIf flag = False Then
For j = 1 To 20
If t = a(j) Then
c = c + 1
b(c) =_________________
End If
Next j
t = ""
flag = True
End If
i = i + 1
Loop
’将b数组中的两位数按数值大小进行升序排序,代码略
For i = 1 To c
t = Val(b(i))
_______________________
Next i
Text2.Text = Str(code)
End Sub
Function decode(num As Integer) As String
Dim mo As Integer
mo = num * num Mod 100
If mo = 0 Then
decode = "00"
ElseIf ___________________ Then
decode = "0" + Trim(Str(mo))
Else
decode = Trim(Str(mo)) 'Trim为去除字符串两端空格的函数
End If
End Function
(1)找出文章(以“.”结束)中所有用英文表示的数字(均为小写,数字范围1≤n≤20),单词与数字对应如下:

(2)将这些数字平方后除以100取余,得到两位数如00,04,21,96。
(3)把这些两位数按升序排成一行,组成一个最小的新数,如果新数开头为0,就去除。
(4)步骤(3)找出的最小数即为密码。
小明按照上述方法,设计了一个解密的VB程序,功能如下:单击“解密”按钮Commandl,程序依次将文本框Textl中以空格分隔的每个英文单词取出,若单词属于数字单词,则按解密步骤进行处理,最后在文本框Text2中输出解密结果。
程序运行效果如图所示,请回答下列问题:

(1)若文章内容为“tom bought two apples and five oranges, which cost ten dollars altogether.”,则破译后的密码应为_____________。
(2)请在划线处填入合适的代码。
Dim a(1 To 20) As String
Private Sub Form_Load()
a(1) = "one": a(2) = "two"
'……将所有数字单词按顺序存入数组a中,代码略
End Sub
Private Sub Command1_Click()
Dim s As String, tmp As String
Dim c as Integer,i As Integer, j As Integer, k As Integer, t As String, ch As As String,code As Long
Dim b(1 To 100) As String 'b数组存放数字单词处理后得到的两位数
s = Text1.Text
c = 0: i = 1: flag = True:t = ""
Do While i <= Len(s)
ch = Mid(s, i, 1)
If ch >= "a" And ch <= "z" Then
t = t + ch
flag = False
ElseIf flag = False Then
For j = 1 To 20
If t = a(j) Then
c = c + 1
b(c) =_________________
End If
Next j
t = ""
flag = True
End If
i = i + 1
Loop
’将b数组中的两位数按数值大小进行升序排序,代码略
For i = 1 To c
t = Val(b(i))
_______________________
Next i
Text2.Text = Str(code)
End Sub
Function decode(num As Integer) As String
Dim mo As Integer
mo = num * num Mod 100
If mo = 0 Then
decode = "00"
ElseIf ___________________ Then
decode = "0" + Trim(Str(mo))
Else
decode = Trim(Str(mo)) 'Trim为去除字符串两端空格的函数
End If
End Function
某排序算法,其VB代码如下:
i = 1
Do While i<= 5
If i = 0 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(5)依次为:“0,61,22,43,89,27”,经过该程序段处理后,数组元素a(4)的值为( )
i = 1
Do While i<= 5
If i = 0 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(5)依次为:“0,61,22,43,89,27”,经过该程序段处理后,数组元素a(4)的值为( )
A.43 |
B.89 |
C.61 |
D.27 |
有如下VB程序段:
For i = 1 To 2
For j = 5 To i + 1 Step -1
If d(j) >d(i) Then
t = d(j): d(j) = d(i): d(i) = t
End If
Next j
List1.additem str(d(i+1))
Next i
数组元素d(1)到d(5)的值依次为34,25,46,17,78,经过该程序段“加工”后,则List1列表框中显示的结果为( )
For i = 1 To 2
For j = 5 To i + 1 Step -1
If d(j) >d(i) Then
t = d(j): d(j) = d(i): d(i) = t
End If
Next j
List1.additem str(d(i+1))
Next i
数组元素d(1)到d(5)的值依次为34,25,46,17,78,经过该程序段“加工”后,则List1列表框中显示的结果为( )
A.78 46 34 17 25 | B.25 34 |
C.17 25 34 46 78 | D.78 46 |