#includestdio.h#includequeue#includealgorithm#includeiteratorusingnamespacestd;structJJB{intJobNum;//任务号intArriveTime;//到达时刻intRunTime;//运行时间intResponTime;//响应时间intLeaveTime;//离开时间intWTime;//周转时间intt2;//在队列还能多少时间intt4;intt8;inttf;intd;//数据存储位置};voidinit(JJB*p)//数据读入,初始化{inta[3];//任务号,到达时刻,运行时间scanf(%d%d%d,&a[0],&a[1],&a[2]);p-JobNum=a[0];p-ArriveTime=a[1];p-RunTime=a[2];p-ResponTime=-1;p-LeaveTime=-1;p-WTime=-1;p-t2=2;p-t4=4;p-t8=8;p-tf=0;}intcmd(JJBa,JJBb)//用于sort的比较{returna.ArriveTimeb.ArriveTime;}intcmd2(JJBa,JJBb)//用于sort的比较{returna.LeaveTimeb.LeaveTime;}intmain(){intn;//任务数量inti,t;JJBmc[100];printf(输入数字n\n);scanf(%d,&n);printf(输入%d组数据\n,n);printf(任务号到达时刻运行时间\n,n);for(i=0;in;i++){init(&mc[i]);}sort(mc,mc+n,cmd);//按到达时刻排序queuestructJJBq2,q4,q8,qf;intsumtime=0;for(i=0;in;i++){mc[i].d=i;sumtime+=mc[i].RunTime;}intcount=0;//数据存储序号,mc[count]JJBq;intm=n;//控制循环t=-1;while(m){t++;while(mc[count].ArriveTime==t){q2.push(mc[count]);count++;}if(!q2.empty()){q=q2.front();mc[q.d].t2--;if(mc[q.d].t2==1)//任务开始{mc[q.d].ResponTime=t-mc[q.d].ArriveTime;}if(mc[q.d].RunTime+mc[q.d].t2-2==0)//如果任务结束{mc[q.d].LeaveTime=t+1;mc[q.d].WTime=mc[q.d].LeaveTime-mc[q.d].ArriveTime;m--;q2.pop();continue;}if(mc[q.d].t2==0)//任务未结束{q2.pop();q4.push(q);}}elseif(!q4.empty()){q=q4.front();mc[q.d].t4--;if(mc[q.d].RunTime+mc[q.d].t4-6==0)//如果任务结束{mc[q.d].LeaveTime=t+1;mc[q.d].WTime=mc[q.d].LeaveTime-mc[q.d].ArriveTime;m--;q4.pop();continue;}if(mc[q.d].t4==0)//任务未结束{q4.pop();q8.push(q);}}elseif(!q8.empty()){q=q8.front();mc[q.d].t8--;if(mc[q.d].RunTime+mc[q.d].t8-14==0)//如果任务结束{mc[q.d].LeaveTime=t+1;mc[q.d].WTime=mc[q.d].LeaveTime-mc[q.d].ArriveTime;m--;q8.pop();continue;}if(mc[q.d].t8==0)//任务未结束{q8.pop();qf.push(q);}}elseif(!qf.empty()){q=qf.front();mc[q.d].tf++;if(mc[q.d].RunTime-14==mc[q.d].tf)//如果任务结束{mc[q.d].LeaveTime=t+1;mc[q.d].WTime=mc[q.d].LeaveTime-mc[q.d].ArriveTime;m--;qf.pop();continue;}}}sort(mc,mc+n,cmd2);printf(任务号响应时间离开时刻周转时间\n);for(i=0;in;i++)printf(%10d%10d%10d%10d\n,mc[i].JobNum,mc[i].ResponTime,mc[i].LeaveTime,mc[i].WTime);return0;}/*6103212341545256661221018328931840256206156789888951102030*/