#include<stdio.h> #include<string.h> #define N 100 struct JCB{ char name[10]; int atime; int stime; int ftime; float ztime; float dcztime; }; JCB a[N]; void FCFS(int number,JCB a[N]); void main() { int number,i; printf("please input the number of the job: "); scanf("%d",&number); for(i=0;i<number;i++) { printf("name:"); scanf("%s",&a[i].name); printf("atime:"); scanf("%d",&a[i].atime); printf("stime:"); scanf("%d",&a[i].stime); } FCFS(number,a); } void FCFS(int number, JCB a[N]) { int i,j,l,y; char k[N]; for(i=0;i<number;i++) //按进程到达时间的先后排序 { //如果两个进程同时到达,按在屏幕先输入的先运行 for(j=i+1;j<number;j++) { if(a[j].atime<a[i].atime) { l=a[j].atime; a[j].atime=a[i].atime; a[i].atime=l; y=a[j].stime; a[j].stime=a[i].stime; a[i].stime=y; strcpy(k,a[j].name); strcpy(a[j].name,a[i].name); strcpy(a[i].name,k); } } } for(i=0;i<number;i++) { a[i].ftime=a[i].atime+a[i].stime; a[i].ztime=a[i].ftime-a[i].atime; } for(i=0;i<number;i++) { // a[i].ftime=a[i].atime+a[i].runtime; printf("%5s%5d%5d\n",a[i].name,a[i].atime,a[i].stime); // a[i+1].atime=a[i].ftime; } }
做了,先来先服务的排序,还没完成先来先服务,不太会做。
时间: 2024-11-03 21:41:00