#includestdio.hstructzgxyb{charname[10];floatarrivetime;floatservicetime;floatstarttime;floatfinishtime;floatzztime;floatdqzztime;};zgxyba[100];voidinput(zgxyb*p,intN){inti;printf(intputtheprocess'sname&arrivetime&servicetime:\nforexmple:a0100\n);for(i=0;i=N-1;i++){printf(inputthe%dthprocess'sinformation:\n,i+1);scanf(%s%f%f,&p[i].name,&p[i].arrivetime,&p[i].servicetime);}}voidPrint(zgxyb*p,floatarrivetime,floatservicetime,floatstarttime,floatfinishtime,floatzztime,floatdqzztime,intN){intk;printf(runorder:);printf(%s,p[0].name);for(k=1;kN;k++){printf(--%s,p[k].name);}printf(\ntheprocess'sinformation:\n);printf(\nname\tarrive\tservice\tstart\tfinish\tzz\tdqzz\n);for(k=0;k=N-1;k++){printf(%s\t%-.2f\t%-.2f\t%-.2f\t%-.2f\t%-.2f\t%-.2f\t\n,p[k].name,p[k].arrivetime,p[k].servicetime,p[k].starttime,p[k].finishtime,p[k].zztime,p[k].dqzztime);}}//按到达时间排序voidsort(zgxyb*p,intN){for(inti=0;i=N-1;i++)for(intj=0;j=i;j++)if(p[i].arrivetimep[j].arrivetime){zgxybtemp;temp=p[i];p[i]=p[j];p[j]=temp;}}//yunxingjieduanvoiddeal(zgxyb*p,floatarrivetime,floatservicetime,floatstarttime,floatfinishtime,float&zztime,float&dqzztime,intN){intk;for(k=0;k=N-1;k++){if(k==0){p[k].starttime=p[k].arrivetime;p[k].finishtime=p[k].arrivetime+p[k].servicetime;}else{p[k].starttime=p[k-1].finishtime;p[k].finishtime=p[k-1].finishtime+p[k].servicetime;}}for(k=0;k=N-1;k++){p[k].zztime=p[k].finishtime-p[k].arrivetime;p[k].dqzztime=p[k].zztime/p[k].servicetime;}}voidZGXYB(zgxyb*p,intN){floatarrivetime=0,servicetime=0,starttime=0,finishtime=0,zztime=0,dqzztime=0;sort(p,N);for(intm=0;mN-1;m++){if(m==0)p[m].finishtime=p[m].arrivetime+p[m].servicetime;elsep[m].finishtime=p[m-1].finishtime+p[m].servicetime;inti=0,n;for(n=m+1;n=N-1;n++){if(p[n].arrivetime=p[m].finishtime)i++;}floatmax=(p[m].finishtime-p[m+1].arrivetime)/p[m+1].servicetime;//第m+1个的响应比intfollow=m+1;for(intk=m+1;km+i;k++){if(max=(p[m].finishtime-p[k+1].arrivetime)/p[k+1].servicetime){max=(p[m].finishtime-p[k+1].arrivetime)/p[k+1].servicetime;follow=k+1;}}zgxybtemp;temp=p[m+1];p[m+1]=p[follow];p[follow]=temp;}deal(p,arrivetime,servicetime,starttime,finishtime,zztime,dqzztime,N);Print(p,arrivetime,servicetime,starttime,finishtime,zztime,dqzztime,N);}voidmain(){intN;printf(------高响应比调度算法------\n);printf(inputtheprocess'snumber:\n);scanf(%d,&N);input(a,N);zgxyb*c=a;ZGXYB(c,N);}