修改时间:2024-07-13 浏览次数:142 类型:高考模拟
For i = 1 To 5
k = i
For j = i + 1 To 6
If a(j) Mod 3 <= a(k) Mod 3 Then k = j
Next j
tmp = a(i): a(i) = a(k): a(k) = tmp
Next i
数组元素 a(1)~a(6)的值依次为“62,54,35,67,15,34”。执行该程序段后,a(1)~a(6)的值依次为( )
Key = Val (Text2. Text)
i = 1
j = 9
flag = False
Do While i <= j And flag = False
m= (i+j) \ 2
If Then
j= m - 1
Else If Then
i = m+1
Else
If Then
j = m - 1
Else If Then
i = m+1
Else
flag = True
End If
End If
Loop
If flag Then Text3. Text =“在第”+ Str(m) +“个”Else Text3. Text =“找不到”
上述程序段中方框处可选语句为
①Key \ 10 > a(m) \ 10 ②Key \ 10 < a(m) \ 10
③Key Mod 10 < a(m) Mod 10 ④Key Mod 10 > a(m) Mod 10
则方框处处语句依次为( )
Private sub command1_click()
Dim a(1 to 20) as integer,b(1 to 20) as integer,i as integer
Dim j as integer,t as integer,p as integer,k as integer,xiaofen as integer
‘从文本框读取AB两队各场的比分分别存数组a、b,场次k,代码略
For i=1 to k-1
For j= 1 to ①
If ② then
t=a(j):a(j)=a(j+1):a(j+1)=t
t=b(j):b(j)=b(j+1):b(j+1)=t
End if
Next j
Next i
p=0 : xiaofen=0
For i=1 to k
If a(i)>b(i) then ③
xiaofen = xiaofen+a(i)-b(i)
List1.Additem str(a(i)) + “:”+ str(b(i))
Next i
If p*2>k or k=p*2 and xiaofen>0 then
Text2.text = “A队获胜”
Elseif then
Text2.text = “B队获胜”
Else
Text2.text = “两队平局”
End if
End sub
① ② ③
1)上靠:若退的房间号为3,则原来登记的记录变为1_3,6_3,10_1;
2)下靠:若退的房间号为5,则原来登记的记录变为1_2,5_4,10_1;
3)上下靠:若退的房间号为9,则原来登记的记录变为1_2,6_5;
4)上下都不靠:若退的房间号为4,则原来登记的记录变为1_2,4_1,6_3,10_1
据上述规则,小明编写了相应的VB程序,程序启动时读入空房间数据,并在列表框List1中显示,在文本框Text11中输入退房号,单击“退房”按钮后更新列表框List1中的数据。程序界面如图所示,请回答下列问题:
| |
Dim a(0 To 10) As Integer ‘保存第i条记录的开始房间号
Dim b(0 To 10) As Integer ‘保存第i条记录的房间数
Dim sp As Integer
Private Sub Form_load()
‘程序启动时从数据库读取原始k条记录,依次存入a(1),b(1),a(2),b(2),...a(k),b(k)代码略
a(0)=0: b(0)=0: sp=k+1: a(sp)=0: b(sp)=0
End sub
Private Sub Command1_Click()
Dim i As Integer, j As Integer
c = Val(Text1.Text)
i = 1
Do While a(i) < c
i = i + 1
Loop
i = i - 1
'处理退房登记问题
If a(i) + b(i) = c Then
If a(i + 1) = c + 1 Then ‘处理第3种情况
For j = i + 1 To sp - 1
a(j) = a(j + 1): b(j) = b(j + 1)
Next j
sp = sp - 1
Else ‘处理第1种情况
b(i) = b(i) + 1
End If
ElseIf c + 1 = a(i + 1) Then ‘处理第2种情况
a(i + 1) = c: b(i + 1) = b(i + 1) + 1
Else
For j =
a(j) = a(j - 1): b(j) = b(j - 1)
Next j
a(i + 1) = c: b(i + 1) = 1:
End If
List1.Clear
For i = 1 To sp - 1
List1.AddItem "" & Str(i) & Str(a(i)) & Str(b(i))
Next i
End Sub
试题篮