题目9提交
This commit is contained in:
parent
7d68c1e323
commit
7de4d5ba6c
27
计算机基础/题目9.py
Normal file
27
计算机基础/题目9.py
Normal file
@ -0,0 +1,27 @@
|
||||
def 电梯调度():
|
||||
当前位置, 请求数量 = map(int, input().split())
|
||||
请求序列 = list(map(int, input().split()))
|
||||
移动方向 = int(input())
|
||||
|
||||
大于当前位置 = [x for x in 请求序列 if x > 当前位置]
|
||||
小于当前位置 = [x for x in 请求序列 if x < 当前位置]
|
||||
等于当前位置 = [x for x in 请求序列 if x == 当前位置]
|
||||
|
||||
大于当前位置.sort()
|
||||
小于当前位置.sort(reverse=True)
|
||||
|
||||
结果 = []
|
||||
|
||||
if 等于当前位置:
|
||||
结果.extend(等于当前位置)
|
||||
|
||||
if 移动方向 == 1:
|
||||
结果.extend(大于当前位置)
|
||||
结果.extend(小于当前位置)
|
||||
else:
|
||||
结果.extend(小于当前位置)
|
||||
结果.extend(大于当前位置)
|
||||
|
||||
print(' '.join(map(str, 结果)))
|
||||
|
||||
电梯调度()
|
Loading…
x
Reference in New Issue
Block a user