管理员从系统中导出某天0点该停车场的剩余车位与当天0点到24点之间进出该停车场的车辆数据,车辆数据包含车牌、到达时间、驶入时间、驶出时间(驶出时间为空字符串表示车辆未驶出),车辆数据已按车辆驶入时间升序排列。
编写程序模拟停车过程,请回答下列问题。
nowt=input("请输入查询空闲车位的时刻:")
#读取车辆数据存入列表data,列表每个元素包含车牌、到达时间、驶入时间、驶出时间。代码略。
hist="2023-3-23-00:00:00" #截止到"2023-3-23-00:00:00",停车场内共有剩余车位231个。
num=231
for i in range(len(data)):
if data[i][3]<=nowt and data[i][3]!="":
if data[i][2]<hist:
甲
:
if data[i][2]>=hist:
乙
①要完成上述功能,则程序段中线处甲、乙依次填入的语句为(单选,填字母)。
A .甲:num-=1 乙:num+=1
B .甲:num+=1 乙:num-=1
②若将程序段加框处代码改成“else”,则下列对结果num的说法最合理的是(单选,填字母)。
A.num可能比原来的值小 B.num的值不变 C.num可能比原来的值大
def money(t1,t2):
#根据时间t1和t2计算车辆的停车费用并返回,代码略。
def team(outt,i,head):
p=q=head
while p!=-1 and data[p][2]<outt:
q=p;p=data[p][3]
if p==q:
head=i
else:
data[q][3]=i
data[i].append(p)
return head
#读取车辆数据存入列表data,列表每个元素的数据项依次为车牌、到达时间、驶出时间。代码略。
#注:3月23日前驶入车辆的到达时间已经处理为当日实际驶入时间。
hist="2023-3-23-00:00:00" #截止到"2023-3-23-00:00:00",停车场内共有剩余车位231个。
num=231
total=0
n=len(data);head=-1
for i in range(n):
if data[i][2]!="":
arrt=data[i][1];outt=data[i][2]
if arrt<hist:
head=team(outt,i,head)
else:
while head!=-1 and :
total+=money(data[head][1],data[head][2])
head=data[head][3]
num+=1
if num==0:
total+=money(data[head][1],data[head][2])
head=data[head][3]
else:
num-=1
head=team(outt,i,head)
else:
while head!=-1:
total+=money(data[head][1],data[head][2])
head=data[head][3]
print("本日总收入为:",total,"元。")