鱼C论坛

 找回密码
 立即注册
查看: 1869|回复: 5

PTA 操作系统 作业调度算法--先来先服务

[复制链接]
发表于 2020-11-21 22:26:31 | 显示全部楼层 |阅读模式

马上注册,结交更多好友,享用更多功能^_^

您需要 登录 才可以下载或查看,没有账号?立即注册

x
  1. #include <iostream>
  2. #include <iomanip>
  3. using namespace std;

  4. void Scheduling(char name[], int table[][2], int col);

  5. int main(){
  6.     int thread;
  7.     cin >> thread;
  8.     char *name = new char[thread];
  9.     int (*table)[2] = new int[thread][2];
  10.     for(int i = 0; i < thread; i++)
  11.         cin >> name[i];
  12.     for(int i = 0; i < 2; i++){
  13.         for(int j = 0; j < thread; j++)
  14.             cin >> table[j][i];
  15.     }
  16.     Scheduling(name, table, thread);
  17.     return 0;
  18. }

  19. void Scheduling(char name[], int table[][2], int col){
  20.     cout << "作 业 名:";
  21.     for(int i = 0; i < col; i++){
  22.         if(i != 0) cout << " ";
  23.         cout << name[i];
  24.     }
  25.     cout << endl;
  26.     cout << "到达时间:";
  27.     for(int i = 0; i < col; i++){
  28.         if(i != 0) cout << " ";
  29.         cout << table[i][0];
  30.     }
  31.     cout << endl;
  32.     cout << "服务时间:";
  33.     for(int i = 0; i < col; i++){
  34.         if(i != 0) cout << " ";
  35.         cout << table[i][1];
  36.     }
  37.     cout << endl;

  38.     int *finish = new int[col];
  39.     finish[0] = table[0][0] + table[0][1];
  40.     for(int i = 1; i < col; i++)
  41.         finish[i] = finish[i-1] + table[i][1];
  42.     int *turnover = new int[col];
  43.     for(int i = 0; i < col; i++)
  44.         turnover[i] = finish[i] - table[i][0];
  45.     double *power = new double[col];
  46.     for(int i = 0; i < col; i++)
  47.         power[i] = (double)turnover[i]/table[i][1];
  48.     cout << "完成时间:";
  49.     for(int i = 0; i < col; i++){
  50.         if(i != 0) cout << " ";
  51.         cout << finish[i];
  52.     }
  53.     cout << endl;
  54.     cout << "周转时间:";
  55.     for(int i = 0; i < col; i++){
  56.         if(i != 0) cout << " ";
  57.         cout << turnover[i];
  58.     }
  59.     cout << endl;
  60.     cout << "带权周转时间:";
  61.     for(int i = 0; i < col; i++){
  62.         if(i != 0) cout << " ";
  63.         cout.setf(ios::fixed);
  64.         cout << setprecision(2) << power[i];
  65.     }
  66.     cout << endl;
  67. }
复制代码

在PTA提交的时候,出现4种情况
360截图20201121222425007.png
只得了case0的分,请大佬们说明其他3种情况是什么,并提出改正。
谢谢
想知道小甲鱼最近在做啥?请访问 -> ilovefishc.com
回复

使用道具 举报

发表于 2020-11-21 22:29:57 | 显示全部楼层
题目是啥
想知道小甲鱼最近在做啥?请访问 -> ilovefishc.com
回复 支持 反对

使用道具 举报

 楼主| 发表于 2020-11-21 22:31:32 | 显示全部楼层
想知道小甲鱼最近在做啥?请访问 -> ilovefishc.com
回复 支持 反对

使用道具 举报

发表于 2020-11-22 21:52:27 | 显示全部楼层
你有对作业按照到达时间排序吗?
想知道小甲鱼最近在做啥?请访问 -> ilovefishc.com
回复 支持 反对

使用道具 举报

 楼主| 发表于 2020-11-23 15:48:57 | 显示全部楼层
赚小钱 发表于 2020-11-22 21:52
你有对作业按照到达时间排序吗?

已排好序
想知道小甲鱼最近在做啥?请访问 -> ilovefishc.com
回复 支持 反对

使用道具 举报

发表于 2020-11-29 11:01:31 | 显示全部楼层
sche.PNG

将代码做个备份。

恕我眼拙,能否告知从第几行到第几行是排序的逻辑。
想知道小甲鱼最近在做啥?请访问 -> ilovefishc.com
回复 支持 反对

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

小黑屋|手机版|Archiver|鱼C工作室 ( 粤ICP备18085999号-1 | 粤公网安备 44051102000585号)

GMT+8, 2024-3-29 17:25

Powered by Discuz! X3.4

© 2001-2023 Discuz! Team.

快速回复 返回顶部 返回列表