From 7de4d5ba6c1ce7af1353cf18f7d6c96afdddd1c6 Mon Sep 17 00:00:00 2001 From: GuanM <30427262+sxhoio@users.noreply.github.com> Date: Thu, 31 Oct 2024 17:49:35 +0800 Subject: [PATCH] =?UTF-8?q?=E9=A2=98=E7=9B=AE9=E6=8F=90=E4=BA=A4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- 计算机基础/题目9.py | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) create mode 100644 计算机基础/题目9.py 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