操作系统使用时间片轮转调度算法管理进程。每个时间片内,CPU 执行当前进程 1 个单位时间,然后将进程移到队列尾部(如果未执行完)。请模拟这个调度过程,输出每个时间片的执行情况和进程完成信息。
输入包含多行: 第一行:整数 N(1 ≤ N ≤ 100),表示进程数量 接下来 N 行:每行两个整数 id 和 t(1 ≤ id ≤ 1000,1 ≤ t ≤ 100),表示进程 id 及其所需的总时间片数
对于每个时间片,输出一行执行信息: Time slice x: Process y is running, remaining time: z 其中 x 是当前时间片编号,y 是进程 id,z 是剩余时间片数。 如果进程在当前时间片结束后完成,紧接着输出一行: Process y completed 最后输出一行总时间: All processes completed in x time units
3 1 3 2 2 3 4
Time slice 1: Process 1 is running, remaining time: 2 Time slice 2: Process 2 is running, remaining time: 1 Time slice 3: Process 3 is running, remaining time: 3 Time slice 4: Process 1 is running, remaining time: 1 Time slice 5: Process 2 is running, remaining time: 0 Process 2 completed Time slice 6: Process 3 is running, remaining time: 2 Time slice 7: Process 1 is running, remaining time: 0 Process 1 completed Time slice 8: Process 3 is running, remaining time: 1 Time slice 9: Process 3 is running, remaining time: 0 Process 3 completed All processes completed in 9 time units