#include #include #include #include struct mystr { int a, b; }; mystr arr[10]; int rep,notadd=0,tfadd=0,po,cannotadd=0,vb; int nota[50],tfa[50],cannota[50],number[50],poarr[20000]; //================================================================== int add( mystr val) { if(val.b==0) { cannotadd++; val.a=0; return 0; } else if(po>9) { notadd++; return 0; } else if(val.a>0) { arr[po++]=val; return 1; } return 1; } //================================================================== void del( int pos) { int k; for(k=pos;k<9;k++) arr[k]=arr[k+1]; arr[9].a=0; arr[9].b=0; po--; // } } //================================================================== void dec() { int p; if (arr[0].b==0 && arr[0].a==0) return ; for(p=9;p>=0;p--) if (arr[p].b==1) { tfadd++; del(p); } else if(arr[p].b>1 && arr[p].a!=0) arr[p].b--; } //================================================================== void frandom() { float res,con=0.0; int arrco=0,l; mystr st; con=(float)rep/50; res=con; randomize(); for(int i=0; i<=rep; i++) { st.a=rand() % 100; st.b=rand() % 17; dec(); add(st); poarr[vb++]=po; //add(st); if(po==10) po=po; for(l=0;l<=9,arr[l].a!=0, arr[l].b!=0;l++) printf("(%d,%d)",arr[l].a,arr[l].b); printf("\n"); if (i==int(res)) { nota[arrco]=notadd; tfa[arrco]=tfadd; cannota[arrco]=cannotadd; number[arrco++]=i; res+=con; } } } //================================================================== void main() { FILE *stream; textcolor(15); textbackground(9); clrscr(); po=0; printf("no. repeat:\t"); scanf("%d",&rep); frandom(); stream = fopen("Queue.xls", "w+"); fprintf(stream, "REG1\t\tBE.0\t\tREG2\t\tBE.F\t\t\n"); fprintf(stream, "--------------------------------------------------------\n"); for(int ind=1; ind<50 ; ind++) fprintf(stream, "%d\t\t %d\t\t %d\t\t %d\t\t\n", number[ind], cannota[ind], tfa[ind], nota[ind]); fclose(stream); getch(); clrscr(); printf("\n\n\n\n\n\n\n\n -------------(((CSP.PARSIBLOG.COM)))------------"); printf("\n\n\n\n\n\n\n\n ************((((((( RESULT IS )))))))************"); printf("\n\n\n\n\n\n\n\n\n\n can't add in Queue beacuse val=0 : %d",cannota[49]); printf("\n\n\n _____________________________________________________________"); printf("\n\n\n add & delete in Queue: %d",tfa[49]); printf("\n\n\n _____________________________________________________________"); printf("\n\n\n can't add in Queue because Queue is full : %d\n",nota[49]); //for(ind=0; ind<10 ; ind++) //printf("%d\t", poarr[ind]); getch(); }