输入N(N>0)个作业,输入每个作业的名字,到达时间,服务时间,按照服务时间与到达时间排序,计算每个作业的完成时间,周转时间,带权周转时间(保留2位小数)。 输入格式: 第一行输入作业数目,第二行输入作业的名字,第三行输入到达时间,第四行输入服务时间。 输出格式: 按照到达时间从小到大排序,第一行输出作业的名字,第二行输出到达时间,第三行输出服务时间,第四行输出完成时间,第五行输出完成时间,第六行输出带权周转时间。 输入样例: 在这里给出一组输入。例如: 5 A B C D E 0 1 2 3 4 4 3 1 2 4 输出样例: 在这里给出相应的输出。例如: 作 业 名:A B C D E 到达时间:0 1 2 3 4 服务时间:4 3 1 2 4 完成时间:4 10 5 7 14 周转时间:4 9 3 4 10 带权周转时间:1.00 3.00 3.00 2.00 2.50
时间: 2023-06-16 15:05:13 浏览: 44
以下是实现该功能的 Python 代码:
```python
n = int(input()) # 输入作业数目
jobs = input().split() # 输入作业名字
arr_times = list(map(int, input().split())) # 输入到达时间
ser_times = list(map(int, input().split())) # 输入服务时间
# 将作业按照到达时间从小到大排序
jobs_with_time = [(jobs[i], arr_times[i], ser_times[i]) for i in range(n)]
jobs_with_time.sort(key=lambda x: x[1])
# 计算完成时间,周转时间,带权周转时间
finish_times = [0] * n
turnaround_times = [0] * n
weighted_turnaround_times = [0] * n
for i in range(n):
if i == 0:
finish_times[i] = jobs_with_time[i][1] + jobs_with_time[i][2]
else:
finish_times[i] = max(jobs_with_time[i][1], finish_times[i-1]) + jobs_with_time[i][2]
turnaround_times[i] = finish_times[i] - jobs_with_time[i][1]
weighted_turnaround_times[i] = round(turnaround_times[i] / jobs_with_time[i][2], 2)
# 输出结果
print("作 业 名:" + " ".join(jobs))
print("到达时间:" + " ".join(map(str, arr_times)))
print("服务时间:" + " ".join(map(str, ser_times)))
print("完成时间:" + " ".join(map(str, finish_times)))
print("周转时间:" + " ".join(map(str, turnaround_times)))
print("带权周转时间:" + " ".join(map(str, weighted_turnaround_times)))
```
输入样例:
```
5
A B C D E
0 1 2 3 4
4 3 1 2 4
```
输出样例:
```
作 业 名:A B C D E
到达时间:0 1 2 3 4
服务时间:4 3 1 2 4
完成时间:4 10 5 7 14
周转时间:4 9 3 4 10
带权周转时间:1.0 3.0 3.0 2.0 2.5
```
相关推荐
![java](https://img-home.csdnimg.cn/images/20210720083646.png)
![.pdf](https://img-home.csdnimg.cn/images/20210720083646.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)