精華區beta b92902xxx 關於我們 聯絡資訊
# include <stdio.h> int main () { int l, s, m, i ,j, k; int a[300];/* count */ printf("Please input the number of boxes for L,M,S size:"); scanf("%d %d %d", &l, &m, &s); while (l>0 || m>0 || s>0) { for( i = 0;i < 300; i++)/* let the origin value of a[] be 25*/ a[i]=25; j = 0; /*counter j, count the arry */ /*let 8x+5y+2z=25 */ if( m > 0 )/* if m>0, the a[] value could be 0 */ { while( l>=2 && m>=1 && s>=2 ) /*2,1,2*/ { l = l-2; m = m-1; s = s-2; a[j] = 0; j++; } while( l>=1 && m>=1 && s>=6) /*1,1,6*/ { l = l-1; m = m-1; s = s-6; a[j] = 0; j++; } while( l>=1 && m>=3 && s>=1) /*1,3,1*/ { l = l-1; m = m-3; s = s-1; a[j] = 0; j++; } while( m>=1 && s>=10) /*0,1,20*/ { m = m-1; s = s-10; a[j]=0; j++; } while( m>=3 && s>=5) /*0,3,5*/ { m = m-3; s = s-5; a[j] = 0; j++; } while(m>=5) /*0,5,0*/ { m = m-5; a[j] = 0; j++; } } while( l > 0 || m > 0 || s > 0)/*鈭弑뢃怎뎟众reedy鲳Ꞌ*/ { while ( a[j] >= 8 && l > 0 ) { a[j] = a[j]-8; l = l - 1; } while ( a[j] >= 5 && m > 0 ) { a[j] = a[j] - 5; m = m - 1; } while (a[j] >= 2 && s > 0 ) { a[j] = a[j] - 2; s = s - 1; } if ( a[j] < 2 ) j++; if ( a[j] < 5 && s == 0 ) j++; if ( a[j] < 8 && s == 0 && m == 0) j++; } if ( a[j] == 25 ) j--; printf("The total packages you need is %d \n",j+1); printf("The volume left in each package is :\n"); for (k = 0 ; k <= j ; k ++) printf("Pack %d: %d\n",k+1,a[k]); printf("Please input the number of boxes for L,M,S size:"); scanf("%d %d %d", &l, &m, &s); } if (l = 0 && m == 0 && s == 0 ) printf("The program is terminate."); else if (l < 0 || m < 0 || s < 0) printf("Enter error, please try again."); }