From c593f3b0e9ac2f8367700343d079fe26f1d2cf5a Mon Sep 17 00:00:00 2001 From: GuanM <30427262+sxhoio@users.noreply.github.com.> Date: Thu, 7 Nov 2024 16:53:32 +0800 Subject: [PATCH] =?UTF-8?q?=E9=A2=98=E7=9B=AE4=E5=AE=8C=E6=88=90?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- 操作系统/题目4.py | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) create mode 100644 操作系统/题目4.py diff --git a/操作系统/题目4.py b/操作系统/题目4.py new file mode 100644 index 0000000..67c0732 --- /dev/null +++ b/操作系统/题目4.py @@ -0,0 +1,24 @@ +def 计算资源需求(): + 可用资源 = list(map(int, input().split())) + 进程列表 = [] + 资源总和 = [0, 0, 0] + + for _ in range(5): + 行数据 = input().split() + 进程 = { + '名称': 行数据[0], + '需求': list(map(int, 行数据[1:4])), + '分配': list(map(int, 行数据[4:7])), + '所需': [] + } + 进程['所需'] = [c - a for c, a in zip(进程['需求'], 进程['分配'])] + 资源总和 = [sum(x) for x in zip(资源总和, 进程['分配'])] + 进程列表.append(进程) + + 资源 = [sum(x) for x in zip(可用资源, 资源总和)] + print(*资源) + for 进程 in 进程列表: + print(进程['名称'], *进程['所需']) + +if __name__ == "__main__": + 计算资源需求()