s=Text1.Text: n=Val(Text2.Text)
p=Len(s) Mod n
If p=0 Then p=n
i=1: cnt=0: m=″″
Do While i <=Len(s)-p+1
If Mid(s, i, p)=Mid(s, i+p, p) Then
cnt=cnt+1
s=Mid(s, 1, i-1)+Mid(s, i+p, Len(s)-p)
Else
i=i+1
End If
Loop
在文本框Text1和Text2中分别输入“abababcccddeffcb”和“2”,执行该程序段后,变量cnt的值是( )
i=1: j=6: flag=False
Key=Val(Text1.Text)
Do While i <=j
m=(i+j) \ 2
If a(m)=Key And flag=fales Then
p=m+1
flag=True
Do While a(p)=a(m)
p=p+1
Loop
ElseIf a(m) >=Key Then
j=j-1
Else
i=i+1
End If
Loop
Label1.Caption=Str(i)+Str(p-1)
若数组元素a(1)到a(8)的值依次为1,3,3,3,7,10,15,20,在文本框Text1中输入3,执行该程序段后,Label1中显示的内容是( )
图a
请回答下列问题:
图b
图a
请回答下列问题:
图b
图c
编写VB程序,实现上述功能。运行程序,在列表框List1中显示45位报名学生的报名序号和所选活动名称。单击“统计”按钮Command1,在列表框List2中显示需要调剂重报活动的学生报名序号。程序运行界面如图所示。
Const n=45
Dim a(1 To n) As String, xh(1 To n) As String
Dim c(1 To 3) As Integer
Private Sub Form_Load()
'在数据库中读取前45位学生的报名序号和所选活动项目名称,分别存入数组xh和数组a,在List1中显示。读取三项活动的限报人数,存入数组c,代码略
End Sub
Private Sub Command1_Click()
Dim b(1 To 3) As Integer, i As Integer, j As Integer, k As Integer
Dim t1 As String, t2 As String
For i=1 To n-1
For j=n To i+1 Step-1
If Then
If a(j)=″A″ Then
b(1)=j-1
Else
b(2)=
End If
t1=a(j): a(j)=a(j-1): a(j-1)=t1
t2=xh(j): xh(j)=xh(j-1): xh(j-1)=t2
End If
Next j
Next i
b(3)=n
i=1: k=1
Do While i <=n
If c(k)=0 And i <=b(k) Then
Do While i <=b(k)
a(i)=″″
i=i+1
Loop
k=k+1
ElseIf Then
k=k+1
Else
i=i+1
End If
Loop
For i=1 To n
If a(i)=″″ Then List2.AddItem xh(i)
Next i
End Sub
编写VB程序,实现上述功能。运行程序,在列表框List1中显示20个监测点的高度(赛段最高点和最低点分别为第1个和第20个监测点)。在文本框Text1中输入设置障碍间距值,单击“设置”按钮Command1,在标签Label5中显示最多设置障碍物数量,若赛道中不含有相对平缓赛段,则在标签Label5中显示0。程序运行界面如图所示。
Const n=20
Dim a(1 To 2*n) As Integer
Private Sub Form_Load()
'在数据库中读取20个监测点名称和其高度值在List1中显示。读取监测点高度值和每个监测点距赛道起点的距离值,存入数组a,其中a(1)、a(3)、a(5)…a(2*i-1)存储监测点高度值,a(2)、a(4)、a(6)…a(2*i)存储每个监测点距赛道起点的距离值,代码略
End Sub
Private Sub Command1_Click()
Dim i As Single, cnt As Integer, p As Integer
Dim max As Integer, s As Integer
s=Val(text1.Text)
smax=0
For i=1 To n
cnt=1
Do While
cnt=cnt+1
Loop
If cnt-1 >=3 And cnt-1 > max Then
max=cnt-1
End If
Next i
i=smax
If i=0 Then
Label5.Caption=″0″
Else
p=0
Do While i >=s
p=p+1
i=i / (p+1)
Loop
Label5.Caption=Str(p-1)
End If
End Sub
Function judge(x As Integer, y As Integer) As Boolean
judge=False
jmin=x: jmax=x
For m=
If a(2*m-1) < a(2*jmin-1) Then jmin=m
If a(2*m-1) > a(2*jmax-1) Then jmax=m
Next m
If a(2*jmax-1)-a(2*jmin-1) <=20 Then judge=True
End Function