您好,欢迎访问三七文档
#includestdio.hvoidPrint(intbc[],intblockCount){for(inti=0;iblockCount;i++){printf(%d,bc[i]);}printf(\n);}boolTravel(intbc[],intblockCount,intx){boolis_found=false;inti;for(i=0;iblockCount;i++){if(bc[i]==x){is_found=true;break;}}returnis_found;}voidOptiomal(intpc[],intbc[],intpageCount,intblockCount){printf(×î¼ÑÖû»Ëã·¨\n);if(pageCount=blockCount){printf(ȱҳ´ÎÊýΪ0\n);printf(ȱҳÂÊΪ\n);}else{intnoPage=0;inti,j,k;for(i=0;ipageCount;i++){if(!Travel(bc,blockCount,pc[i])){if(iblockCount){bc[i]=pc[i];}else{intmax=0;intblockIndex;;for(j=0;jblockCount;j++){for(k=i;kpageCount;k++){if(bc[j]==pc[k]){break;}}if(k=max){max=k;blockIndex=j;}}bc[blockIndex]=pc[i];}noPage++;}}printf(OPTȱҳ´ÎÊýΪ:%d\n,noPage);printf(OPTȱҳÂÊΪ:%.2f%%\n,(float)noPage/pageCount*100);}}intmain(){intpageCount,blockCount,i,pc[100];printf(ÊäÈëÒ³ÃæÊý\n);scanf(%d,&pageCount);printf(ÊäÈëÒ³Ãæ×ßÏò\n);for(i=0;ipageCount;i++){scanf(%d,&pc[i]);}blockCount=3;intbc[100];printf(\n);Optiomal(pc,bc,pageCount,blockCount);return0;}
本文标题:缺页中断统计代码
链接地址:https://www.777doc.com/doc-5020379 .html