题型:综合题 题类:模拟题 难易度:困难
浙江省浦江县高级中学2021届高三上学期信息技术1月仿真模拟考试试卷
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
图 a | 图 b |
t=h
p=d[h][1]
while p != -1 :
q=d[p][1]
p=q
d[t][-1]=-1
试题篮