医院为提升服务质量,编写程序模拟就诊顺序。现获取某医生早上就诊患者的数据,分别为姓名、预约或挂号时间、就诊时长(单位:分钟)。预约挂号数据(准时到达人员数据)如图a所示,直接挂号数据如图b所示。运行程序,输出前三位就诊顺序名单,如图c所示。
![]() | ![]() | ![]() |
图a | 图b | 图c |
(2)定义如下sort(1st)函数,参数1st的每个元素都包含3个数据项,分别为姓名、预约时间、就诊时长。函数功能是将1st的元素根据预约时间进行升序排列,函数返回1st。函数代码如下,请在划线处填入合适的代码。
def sort(lst):
n=len(lst)-1
for i in range(n-1):
for j in range(n,i+1,-1):
if
1st[j], 1st[j-1]=1st[j-1], 1st[j]
return 1st
(3)实现模拟输出就诊顺序的部分Python程序如下,请在划线处填入合适的代码。
def insert(1st, i, head):
curtime=1st[head][1]+int(1st[head][2])#就诊结束时间
if
1st[i]. append(head)
head=i
curtime=1st[i][1]+int(1st[i][2])
i+=1
q=1st[p][3]
while i<=len(lst)-1:
if curtime>=1st[q][1]and q!=-1:#预约人员优先就诊
p=q
q=1st[p][3]
curtime+=int(1st[p][2])
elif curtime>=1st[i][1] or q==-1:
1st[i].append(q)
curtime+=int(1st[i][2])
p=i
i+=1
elif 1st[q][1]<=1st[i][1]:
curtime=1st[q][1]
else:
curtime=1st[i][1]
return 1st
#预约挂号数据转换为列表1st,并将时间转换为分钟,如08:30转为510,代码略
1st=sort(1st)
n=len(1st)-1
for i in range(1,n):
1st[i]. append(i+1) #1st[i]追加一个元素i+1
1st[n]. append(-1)
#将门诊挂号数据合并至列表1st中,列表1st数据如第15题图d所示,代码略
head=1
1st1=insert(1st,n+1,head)
#输出就诊顺序,代码略


同类型试题

y = sin x, x∈R, y∈[–1,1],周期为2π,函数图像以 x = (π/2) + kπ 为对称轴
y = arcsin x, x∈[–1,1], y∈[–π/2,π/2]
sin x = 0 ←→ arcsin x = 0
sin x = 1/2 ←→ arcsin x = π/6
sin x = √2/2 ←→ arcsin x = π/4
sin x = 1 ←→ arcsin x = π/2


y = sin x, x∈R, y∈[–1,1],周期为2π,函数图像以 x = (π/2) + kπ 为对称轴
y = arcsin x, x∈[–1,1], y∈[–π/2,π/2]
sin x = 0 ←→ arcsin x = 0
sin x = 1/2 ←→ arcsin x = π/6
sin x = √2/2 ←→ arcsin x = π/4
sin x = 1 ←→ arcsin x = π/2

