#include<stdio.h>
#include <iostream.h>
void main()
{
int ID[5]={0,1,2,3,4};
int PRIORITY[5]={9,38,30,29,0};
int CPUTIME[5]={0,0,0,0,0};
int ALLTIME[5]={3,3,6,3,4};
int STARTBLOCK[5]={2,-1,-1,-1,-1};
int BLOCKTIME[5]={3,0,0,0,0};
int str[5];//1=READY,0=BLOCK,-1=END
int max5(int PRIORITY50,int PRIORITY51,int PRIORITY52,int PRIORITY53,int PRIORITY54);
int max4(int PRIORITY40,int PRIORITY41,int PRIORITY42,int PRIORITY43);
int max3(int PRIORITY30,int PRIORITY31,int PRIORITY32);
int max2(int PRIORITY20,int PRIORITY21);
int i=1,a,b0,b1,b2,b3,b4,c0,c1,c2,c3,c4;
//===================================================================
if(max5(ALLTIME[0],ALLTIME[1],ALLTIME[2],ALLTIME[3],ALLTIME[4])>0)
{
for(;max5(ALLTIME[0],ALLTIME[1],ALLTIME[2],ALLTIME[3],ALLTIME[4])>0;)
{
if(ALLTIME[0]>0||ALLTIME[1]>0||ALLTIME[2]>0||ALLTIME[3]>0||ALLTIME[4]>0)
a=max5(PRIORITY[0],PRIORITY[1],PRIORITY[2],PRIORITY[3],PRIORITY[4]);
else if(ALLTIME[0]==0||ALLTIME[1]>0||ALLTIME[2]>0||ALLTIME[3]>0||ALLTIME[4]>0)
a=max4(PRIORITY[1],PRIORITY[2],PRIORITY[3],PRIORITY[4]);
else if(ALLTIME[0]>0||ALLTIME[1]==0||ALLTIME[2]>0||ALLTIME[3]>0||ALLTIME[4]>0)
a=max4(PRIORITY[0],PRIORITY[2],PRIORITY[3],PRIORITY[4]);
else if(ALLTIME[0]>0||ALLTIME[1]>0||ALLTIME[2]==0||ALLTIME[3]>0||ALLTIME[4]>0)
a=max4(PRIORITY[0],PRIORITY[1],PRIORITY[3],PRIORITY[4]);
else if(ALLTIME[0]>0||ALLTIME[1]>0||ALLTIME[2]>0||ALLTIME[3]==0||ALLTIME[4]>0)
a=max4(PRIORITY[0],PRIORITY[1],PRIORITY[2],PRIORITY[4]);
else if(ALLTIME[0]>0||ALLTIME[1]>0||ALLTIME[2]>0||ALLTIME[3]>0||ALLTIME[4]==0)
a=max4(PRIORITY[0],PRIORITY[1],PRIORITY[2],PRIORITY[3]);
//===================================================================
else if(ALLTIME[0]==0||ALLTIME[1]==0||ALLTIME[2]>0||ALLTIME[3]>0||ALLTIME[4]>0)
a=max3(PRIORITY[2],PRIORITY[3],PRIORITY[4]);
else if(ALLTIME[0]==0||ALLTIME[1]>0||ALLTIME[2]==0||ALLTIME[3]>0||ALLTIME[4]>0)
a=max3(PRIORITY[1],PRIORITY[3],PRIORITY[4]);
else if(ALLTIME[0]==0||ALLTIME[1]>0||ALLTIME[2]>0||ALLTIME[3]==0||ALLTIME[4]>0)
a=max3(PRIORITY[1],PRIORITY[2],PRIORITY[4]);
else if(ALLTIME[0]==0||ALLTIME[1]>0||ALLTIME[2]>0||ALLTIME[3]>0||ALLTIME[4]==0)
a=max3(PRIORITY[1],PRIORITY[2],PRIORITY[3]);
else if(ALLTIME[0]>0||ALLTIME[1]==0||ALLTIME[2]==0||ALLTIME[3]>0||ALLTIME[4]>0)
a=max3(PRIORITY[0],PRIORITY[3],PRIORITY[4]);
else if(ALLTIME[0]>0||ALLTIME[1]==0||ALLTIME[2]>0||ALLTIME[3]==0||ALLTIME[4]>0)
a=max3(PRIORITY[0],PRIORITY[2],PRIORITY[4]);
else if(ALLTIME[0]>0||ALLTIME[1]==0||ALLTIME[2]>0||ALLTIME[3]>0||ALLTIME[4]==0)
a=max3(PRIORITY[0],PRIORITY[2],PRIORITY[3]);
else if(ALLTIME[0]>0||ALLTIME[1]>0||ALLTIME[2]==0||ALLTIME[3]==0||ALLTIME[4]>0)
a=max3(PRIORITY[0],PRIORITY[1],PRIORITY[4]);
else if(ALLTIME[0]>0||ALLTIME[1]>0||ALLTIME[2]==0||ALLTIME[3]>0||ALLTIME[4]==0)
a=max3(PRIORITY[0],PRIORITY[1],PRIORITY[3]);
else if(ALLTIME[0]>0||ALLTIME[1]>0||ALLTIME[2]>0||ALLTIME[3]==0||ALLTIME[4]==0)
a=max3(PRIORITY[0],PRIORITY[1],PRIORITY[2]);
//====================================================================
else if(ALLTIME[0]==0||ALLTIME[1]==0||ALLTIME[2]==0||ALLTIME[3]>0||ALLTIME[4]>0)
a=max2(PRIORITY[3],PRIORITY[4]);
else if(ALLTIME[0]==0||ALLTIME[1]==0||ALLTIME[2]>0||ALLTIME[3]==0||ALLTIME[4]>0)
a=max2(PRIORITY[2],PRIORITY[4]);
else if(ALLTIME[0]==0||ALLTIME[1]==0||ALLTIME[2]>0||ALLTIME[3]>0||ALLTIME[4]==0)
a=max2(PRIORITY[2],PRIORITY[3]);
else if(ALLTIME[0]==0||ALLTIME[1]>0||ALLTIME[2]==0||ALLTIME[3]==0||ALLTIME[4]>0)
a=max2(PRIORITY[1],PRIORITY[4]);
else if(ALLTIME[0]==0||ALLTIME[1]>0||ALLTIME[2]==0||ALLTIME[3]>0||ALLTIME[4]==0)
a=max2(PRIORITY[1],PRIORITY[3]);
else if(ALLTIME[0]>0||ALLTIME[1]==0||ALLTIME[2]==0||ALLTIME[3]==0||ALLTIME[4]>0)
a=max2(PRIORITY[0],PRIORITY[4]);
else if(ALLTIME[0]>0||ALLTIME[1]==0||ALLTIME[2]==0||ALLTIME[3]>0||ALLTIME[4]==0)
a=max2(PRIORITY[0],PRIORITY[3]);
else if(ALLTIME[0]==0||ALLTIME[1]>0||ALLTIME[2]>0||ALLTIME[3]==0||ALLTIME[4]==0)
a=max2(PRIORITY[1],PRIORITY[2]);
else if(ALLTIME[0]>0||ALLTIME[1]==0||ALLTIME[2]>0||ALLTIME[3]==0||ALLTIME[4]==0)
a=max2(PRIORITY[0],PRIORITY[2]);
else if(ALLTIME[0]>0||ALLTIME[1]>0||ALLTIME[2]==0||ALLTIME[3]==0||ALLTIME[4]==0)
a=max2(PRIORITY[0],PRIORITY[1]);
//====================================================================
else if(ALLTIME[0]>0||ALLTIME[1]==0||ALLTIME[2]==0||ALLTIME[3]==0||ALLTIME[4]==0)
a=PRIORITY[0];
else if(ALLTIME[0]==0||ALLTIME[1]>0||ALLTIME[2]==0||ALLTIME[3]==0||ALLTIME[4]==0)
a=PRIORITY[1];
else if(ALLTIME[0]==0||ALLTIME[1]==0||ALLTIME[2]>0||ALLTIME[3]==0||ALLTIME[4]==0)
a=PRIORITY[2];
else if(ALLTIME[0]==0||ALLTIME[1]==0||ALLTIME[2]==0||ALLTIME[3]>0||ALLTIME[4]==0)
a=PRIORITY[3];
else if(ALLTIME[0]==0||ALLTIME[1]==0||ALLTIME[2]==0||ALLTIME[3]==0||ALLTIME[4]>0)
a=PRIORITY[4];
//===================================================================
if(a==PRIORITY[0])
{
i=0;
PRIORITY[0]-=3;
PRIORITY[3]+=1;PRIORITY[1]+=1;PRIORITY[2]+=1;PRIORITY[4]+=1;
CPUTIME[0]+=1;
ALLTIME[0]-=1;
STARTBLOCK[0]-=1;
STARTBLOCK[3]-=1;STARTBLOCK[1]-=1;STARTBLOCK[2]-=1;STARTBLOCK[4]-=1;
BLOCKTIME[3]-=1;BLOCKTIME[1]-=1;BLOCKTIME[2]-=1;BLOCKTIME[4]-=1;
}
else if(a==PRIORITY[1])
{
i=1;
PRIORITY[1]-=3;
PRIORITY[0]+=1;PRIORITY[2]+=1;PRIORITY[3]+=1;PRIORITY[4]+=1;
CPUTIME[1]+=1;
ALLTIME[1]-=1;
STARTBLOCK[1]-=1;
STARTBLOCK[0]-=1;STARTBLOCK[3]-=1;STARTBLOCK[2]-=1;STARTBLOCK[4]-=1;
BLOCKTIME[0]-=1;BLOCKTIME[3]-=1;BLOCKTIME[2]-=1;BLOCKTIME[4]-=1;
}
else if(a==PRIORITY[2])
{
i=2;
PRIORITY[2]-=3;
PRIORITY[0]+=1;PRIORITY[1]+=1;PRIORITY[3]+=1;PRIORITY[4]+=1;
CPUTIME[2]+=1;
ALLTIME[2]-=1;
STARTBLOCK[2]-=1;
STARTBLOCK[0]-=1;STARTBLOCK[1]-=1;STARTBLOCK[3]-=1;STARTBLOCK[4]-=1;
BLOCKTIME[0]-=1;BLOCKTIME[1]-=1;BLOCKTIME[3]-=1;BLOCKTIME[4]-=1;
}
else if(a==PRIORITY[3])
{
i=3;
PRIORITY[3]-=3;
PRIORITY[0]+=1;PRIORITY[1]+=1;PRIORITY[2]+=1;PRIORITY[4]+=1;
CPUTIME[3]+=1;
ALLTIME[3]-=1;
STARTBLOCK[3]-=1;
STARTBLOCK[0]-=1;STARTBLOCK[1]-=1;STARTBLOCK[2]-=1;STARTBLOCK[4]-=1;
BLOCKTIME[0]-=1;BLOCKTIME[1]-=1;BLOCKTIME[2]-=1;BLOCKTIME[4]-=1;
}
else if(a==PRIORITY[4])
{
i=4;
PRIORITY[4]-=3;
PRIORITY[0]+=1;PRIORITY[1]+=1;PRIORITY[2]+=1;PRIORITY[3]+=1;
CPUTIME[4]+=1;
ALLTIME[4]-=1;
STARTBLOCK[4]-=1;
STARTBLOCK[0]-=1;STARTBLOCK[1]-=1;STARTBLOCK[2]-=1;STARTBLOCK[3]-=1;
BLOCKTIME[0]-=1;BLOCKTIME[1]-=1;BLOCKTIME[2]-=1;BLOCKTIME[3]-=1;
}
if(BLOCKTIME[0]==-1)
BLOCKTIME[0]=0;
if(BLOCKTIME[1]==-1)
BLOCKTIME[1]=0;
if(BLOCKTIME[2]==-1)
BLOCKTIME[2]=0;
if(BLOCKTIME[3]==-1)
BLOCKTIME[3]=0;
if(BLOCKTIME[4]==-1)
BLOCKTIME[4]=0;
if(BLOCKTIME[0]>0)
str[0]=0;
else
if(BLOCKTIME[0]<=0)
str[0]=1;
else
if(ALLTIME[0]<=0)
str[0]=-1;
if(BLOCKTIME[1]>0)
str[1]=0;
else
if(BLOCKTIME[1]<=0)
str[1]=1;
else
if(ALLTIME[1]<=0)
str[1]=-1;
if(BLOCKTIME[2]>0)
str[2]=0;
else
if(BLOCKTIME[2]<=0)
str[2]=1;
else
if(ALLTIME[2]<=0)
str[2]=-1;
if(BLOCKTIME[3]>0)
str[3]=0;
else
if(BLOCKTIME[3]<=0)
str[3]=1;
else
if(ALLTIME[3]<=0)
str[3]=-1;
if(BLOCKTIME[4]>0)
str[4]=0;
else
if(BLOCKTIME[4]<=0)
str[4]=1;
else
if(ALLTIME[4]<=0)
str[4]=-1;
//====================================================================
if(ALLTIME[0]<=0)
{
PRIORITY[0]=0;
ALLTIME[0]=0;
STARTBLOCK[0]=-1;
BLOCKTIME[0]=0;
}
if(ALLTIME[1]<=0)
{
PRIORITY[1]=0;
ALLTIME[1]=0;
STARTBLOCK[1]=-1;
BLOCKTIME[1]=0;
}
if(ALLTIME[2]<=0)
{
PRIORITY[2]=0;
ALLTIME[2]=0;
STARTBLOCK[2]=-1;
BLOCKTIME[2]=0;
}
if(ALLTIME[3]<=0)
{
PRIORITY[3]=0;
ALLTIME[3]=0;
STARTBLOCK[3]=-1;
BLOCKTIME[3]=0;
}
if(ALLTIME[4]<=0)
{
PRIORITY[4]=0;
ALLTIME[4]=0;
STARTBLOCK[4]=-1;
BLOCKTIME[4]=0;
}
//====================================================================
if(STARTBLOCK[0]==-2)
STARTBLOCK[0]=-1;
if(STARTBLOCK[1]==-2)
STARTBLOCK[1]=-1;
if(STARTBLOCK[2]==-2)
STARTBLOCK[2]=-1;
if(STARTBLOCK[3]==-2)
STARTBLOCK[3]=-1;
if(STARTBLOCK[4]==-2)
STARTBLOCK[4]=-1;
//===================================================================
//===================================================================
printf("RUNNING PROG: %d/n",i);
//printf("READY_QUENE:->id%d->id%d->id%d->id%d->id%d/n",b0,b1,b2,b3,b4);
//printf("BLOCK_QUENE:->id%d->id%d->id%d->id%d->id%d/n",c0,c1,c2,c3,c4);
printf("====================================================/n");
printf("ID/t/t%d/t%d/t%d/t%d/t%d/n",ID[0],ID[1],ID[2],ID[3],ID[4]);
printf("PRIORITY/t%d/t%d/t%d/t%d/t%d/n",PRIORITY[0],PRIORITY[1],PRIORITY[2],PRIORITY[3],PRIORITY[4]);
printf("CPUTIME/t/t%d/t%d/t%d/t%d/t%d/n",CPUTIME[0],CPUTIME[1],CPUTIME[2],CPUTIME[3],CPUTIME[4]);
printf("ALLTIME/t/t%d/t%d/t%d/t%d/t%d/n",ALLTIME[0],ALLTIME[1],ALLTIME[2],ALLTIME[3],ALLTIME[4]);
printf("STARTBLOCK/t%d/t%d/t%d/t%d/t%d/n",STARTBLOCK[0],STARTBLOCK[1],STARTBLOCK[2],STARTBLOCK[3],STARTBLOCK[4]);
printf("BLOCKTIME/t%d/t%d/t%d/t%d/t%d/n",BLOCKTIME[0],BLOCKTIME[1],BLOCKTIME[2],BLOCKTIME[3],BLOCKTIME[4]);
printf("STATE/t/t%d/t%d/t%d/t%d/t%d/n",str[0],str[1],str[2],str[3],str[4]);
printf("/t/t1=READY,0=BLOCK,-1=END/n/n/n/n");
}
}
else
printf("/nAll of the PROGS has been finished./n");
}
//===================================================================
int max5(int PRIORITY50,int PRIORITY51,int PRIORITY52,int PRIORITY53,int PRIORITY54)
{
int PRIORITY_max;
if(PRIORITY50>PRIORITY51)
PRIORITY_max=PRIORITY50;
else PRIORITY_max=PRIORITY51;
if(PRIORITY52>PRIORITY_max)
PRIORITY_max=PRIORITY52;
else
if(PRIORITY53>PRIORITY_max)
PRIORITY_max=PRIORITY53;
else
if(PRIORITY54>PRIORITY_max)
PRIORITY_max=PRIORITY54;
else
PRIORITY_max=PRIORITY_max;
return(PRIORITY_max);
}
int max4(int PRIORITY40,int PRIORITY41,int PRIORITY42,int PRIORITY43)
{
int PRIORITY_max;
if(PRIORITY40>PRIORITY41)
PRIORITY_max=PRIORITY40;
else PRIORITY_max=PRIORITY41;
if(PRIORITY42>PRIORITY_max)
PRIORITY_max=PRIORITY42;
else
if(PRIORITY43>PRIORITY_max)
PRIORITY_max=PRIORITY43;
else PRIORITY_max=PRIORITY_max;
return(PRIORITY_max);
}
int max3(int PRIORITY30,int PRIORITY31,int PRIORITY32)
{
int PRIORITY_max;
if(PRIORITY30>PRIORITY31)
PRIORITY_max=PRIORITY30;
else PRIORITY_max=PRIORITY31;
if(PRIORITY32>PRIORITY_max)
PRIORITY_max=PRIORITY32;
else PRIORITY_max=PRIORITY_max;
return(PRIORITY_max);
}
int max2(int PRIORITY20,int PRIORITY21)
{
int PRIORITY_max;
if(PRIORITY20>PRIORITY21)
PRIORITY_max=PRIORITY20;
else PRIORITY_max=PRIORITY21;
return(PRIORITY_max);
}//(使用VC6.0编译)