修改时间:2021-05-28 浏览次数:174 类型:高考模拟
Dim s1 As String, s2 As String, a As Integer, i As Integer, b(1 To 26) As Integer 'b数组初值均为0
s1 = Text1.Text: s2 = Text2.Text
For i= 1 To Len(s1)
a= Asc(Mid(s1, i, 1))-65+ 1
⑴
Next i
For i= 1 To Len(s2)
a= Asc(Mid(s2, i, 1))-65+ 1
⑵
Next i
For i= 1 To 26
If ⑶ Then Exit For
Next i
If ⑷ Then Label1.Caption = "能归为一类" Else Labl1.Caption= "不能归为一类"
填空处的代码可以由以下部分组成:
①b(a)=b(a)+1 ②b(a)=b(a)-1 ③b(i)<>0 ④b(i)=0 ⑤i<=26 ⑥i>26
代码顺序正确的是( )
n=6: c=0: d=0: st=1: ed=n
Do While st < ed
c=c+1
For j=st To ed- 1
d=d+1
If a(j)> a(j+ 1) Then
tmp = a(j): a(i)=a(j+1): a(j+1)= tmp
ed=j
End If
Next j
For j=ed To st+1 Step-1
d=d+ 1
If a(j)< a(j- 1) Then
tmp= a(j): a(i)=a(j- 1): a(j- 1)= tmp
st=j
End If
Next j
Loop
数组元素a(1)到a(6)的值依次为“5,6,12,15,10,8”,程序结束时,c和d的值分别为( )
L=1: R=n+ 1
Do While L< R
m=(L+R)\2
If key > a(m) Then
①
Else
L=m+ 1
End If
Loop
If R= 1 Then
Text2.Text = "数组中所有元素均小于" & Str(key)
Else
Text2.Text= "不小于" & Str(key) & "的下标最大值是: " & Str( ② )
End If
则划线处代码正确的是( )
图a
图b
图a
图b
编写VB程序,实现上述合并功能。运行程序时,将n堆果子的重量从数据库读入到a数组。单击“合并”按钮Command1后,在文本框Text1中输出最小的体力耗费值。请回答下列问题:
Private Sub Form_ Load( )
‘将n堆果子的重量从数据库导入到数组a,代码略。
End Sub
Private Sub Command1_Click( )
Dim f As Boolean
Dim last As Integer
Dim a(1 To n) As Integer
i= 1
Do While i<n And Not f
f=True
For j=n To i+1 Step-1
If a(j)<a(j- 1) Then
t= a(j): a(j)=a(j- 1): a(j-1)=t
last= j
f= False
End If
Next j
Loop
For i= 1 To n-2
tmp=a(i)+a(i+1)
j=
Do While a(j)< tmp
a(j-1)= a(j)
j=j+1
If j=n+ 1 Then Exit Do
Loop
Min=Min+tmp
Next i
Text1.Text = Min
End Sub
现有VB程序用于判断某图能否一笔画成,若能,则通过穷举边的顺序来找到一种合法的路径。如c图有三条边,第1条由①②相连,第2条由④③相连,第3条由③②相连,若边的顺序231就是其中一种合法的边的顺序,代表先描第2条边,再描第3边,最后描第1条边,对应的路径④→③→②→①。在程序运行过程中,在文本框Text1中输入点的个数n,表示图中有n个点编号为1~n。在文本框Text2中输入若干点的编号,每两个点代表一条边(保证输入为偶数个点),以“,”开头,点击“一笔画”按钮Command1后,在Label3中输出结果,在若能一笔画成,则输出一条路径,否则,提示“无法一笔画!”。程序界面如c图:
c图
Dim n As Integer, t As Integer, m As Integer, I As Integer, j As Integer
Dim ans As Integer, u As Integer, st As Integer, p As Long
Dim a(21) As Integer, b(11) As Integer, f(11) As Integer
Dim c(11)As Integer '用于存储构成一笔画各边的序号
Dim s As String, ss As String
Private Sub Command1_Click()
n= Val(Text1.Text)
s= Text2.Text: t= 0
For j= 1 To Len(s)
ch = Mid(s, j, 1)
If ch = "," Then
b(a(t)) = b(a(t)+1
t=t+1
a(t)= 0
Else
a(t)= a(t)*10 + Val(ch)
End If
Next j
: m=t\2: ans=0
st= 1
For i= 1 To n
If b(i) Mod 2=1 Then ans = ans+ 1: st=i
Next i
If ans=0 Or ans=2 Then
For p=1 To m^m '穷举边的顺序
If try(p) Then
u= st: ss = Str(u)
For j=1 To m
If (a(c(j)* 2)<>u) And (a(c(j)*2-1)<>u) Then Exit For
If Then u= a(c(j)*2- 1) Else u=a(c(j)*2)
ss=ss +"->"+ Str(u)
Next j
If j> m Then Exit For
End If
Next p
Else
ss="无法一笔画!"
End If
Label3.Caption=ss
End Sub
Function try(x As Long) As Boolean '生成边的访问顺序,并判断有无重复的边
Dim k As Integer, y As Long
y=x
For k=1 To m
c(k)=y Mod m+1: y-y\m
If f(c(k)) = x Then Exit For
Next k
If k> m Then try=True Else try = False
End Function
试题篮