result = ""
s1 = Text1.Text
s2 = Text2.Text
i = 1
Do While i <= Len(s1)
If Mid(s1,i,Len(s2)) <> s2 Then
result = result + Mid(s1, i, 1)
i = i + 1
Else
i = i + Len(s2)
End If
Loop
在文本框Text1和Text2中分别输入“Pyyesthon”和“yes”,执行该程序段后,变量result的值是( )
i = 1 : n = 5
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
已知数组a中各元素初始值均为0,执行该程序段后,数组a(1)至a(5)各元素值不可能的是( )
'随机产生包含10个整型元素的升序序列,依次存入数组a,代码略
i = 1: j = 10: s = "": c = 0
key = Val(Text1.Text)
Do While i <= j
m = (i + j)\ 2
c = c + 1
s = s + Str(a(m))
If a(m) > key Then j = m - 1 Else i = m + 1
Loop
在文本框 Text1中输入待查找数,执行该程序后,下列说法不正确的是( )
图a |
图b |
小陈设计了VB程序用于解决该问题。程序运行时,在文本框Text1中输入学生的体重数据,用“,”号隔开。在文本框Text2中输入船的最大载重m。单击“计算”按钮Command1,读取学生体重数据到数组a中,并在标签Label1中显示最少分组数。程序运行界面如图所示。请回答下列问题:
Private Sub Command1_Click()
Dim a(1 To 40) As Integer
Dim n As Integer, m As Integer
Dim t As Integer
Dim sum As Integer, c As Integer
Dim s As String, ch As String,
n = 0 : t = 0
s = Text1.Text
m = Val(Text2.Text)
For i = 1 To Len(s)
ch = Mid(s,i,1)
If ch <> "," Then
Else
n = n + 1
a(n) = t
t = 0
End If
Next i
sum = 0 : c = 0
For i = 1 To n
If Then
sum = 0 : c = c + 1
End If
sum = sum + a(i)
Next i
Label1.Caption = "最少分组:" + c
End Sub
小陈按上述要求编写了一个VB程序,功能如下:程序运行时,在列表框List1中显示排序前数据,单击“排序”按钮Command1,在列表框List2中显示排序结果。程序运行界面如图所示。请回答下列问题:
Const n = 200 ’学生数
Const m = 4 ’班级数
Dim xh(1 To n) As String, tmp1(1 To n) As String
Dim score(1 To n) As Integer, tmp2(1 To n) As Integer
Dim class(1 To n) As Integer, tmp3(1 To n) As Integer
Private Sub Form_Load()
'读取学生的学号、班级和成绩数据分别存储在数组xh,class和score中并在List1中显示
'代码略
End Sub
Private Sub Command1_Click()
Dim i As Integer, j As Integer, k As Integer
Dim t3 As Integer, t2 As Integer, t1 As String
Dim c(0 To m + 1) As Integer
For i = 0 To m + 1
c(i) = 0
Next i
For i = 1 To n
c(k) = c(k) + 1
Next i
For i = 1 To m
c(i) = c(i) + c(i - 1)
Next i
For i = n To 1 Step -1
k = class(i)
tmp1(c(k)) = xh(i)
tmp2(c(k)) = score(i)
tmp3(c(k)) = class(i)
Next i
c(m + 1) = n
For k = 1 To m '对每一个班的学生成绩进行排序
For i = c(k) + 1 To c(k + 1) - 1
For j = c(k + 1) To i + 1 Step -1
If Then
t1 = tmp1(j): tmp1(j) = tmp1(j-1): tmp1(j-1) = t1
t2 = tmp2(j): tmp2(j) = tmp2(j-1): tmp2(j-1) = t2
t3 = tmp3(j): tmp3(j) = tmp3(j-1): tmp3(j-1) = t3
End If
Next j
Next i
Next k
'在List2中按统一格式输出排序后数据,代码略
End Sub