diff --git a/计算机基础/题目9.py b/计算机基础/题目9.py new file mode 100644 index 0000000..46f633e --- /dev/null +++ b/计算机基础/题目9.py @@ -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, 结果))) + +电梯调度() \ No newline at end of file