#include<stdio.h>
#define M 20
#define N 3
void FIFO(int a[N],int b[M])
{
int i,j,k;
int c[M]={0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0};
float s;
for(i=0;i<N;i++)
{
a[i]=-1;
//for(j=0;j<=i;j++)
//{
printf("%d ",a[i]);
//}
//printf("\n");
}
printf("\n");
k=N;
for(j=0;j<M;j++)
{
for(i=0;i<N;i++)
if(b[j]==a[i])//命中
{
c[j]=1;
break;
}
if(c[j]==1)
{
for(i=0;i<N;i++)
printf("%d ",a[i]);
}
if(c[j]==0)
{
a[k%N]=b[j];
k++;
for(i=0;i<N;i++)
printf("%d ",a[i]);
}
printf("\n");
}
s=1-k*1.0/M;
//printf("中断次数为%d\n",k);
printf("缺页率为%f\n",s);
}
void main()
{
int a[N]={0,0,0};
int b[M]={7,0,1,2,0,3,0,4,2,3,0,3,2,1,2,0,1,7,0,1};
FIFO(a,b);
}