Online JudgeProblem SetAuthorsOnline ContestsUser
Web Board
Home Page
F.A.Qs
Statistical Charts
Problems
Submit Problem
Online Status
Prob.ID:
Register
Update your info
Authors ranklist
Current Contest
Past Contests
Scheduled Contests
Award Contest
User ID:
Password:
  Register

C语言练习题

Posted by Liuzhaoliang at 2014-09-25 05:19:04 on Problem 2818

int Q,D,N,P,C;

int main()
{
    while(scanf("%d%d%d%d%d",&Q,&D,&N,&P,&C), Q||D||N||P||C){
        int q,d,n,p;
        int best = INT_MAX;
        for(int i=0;i<=Q && i*25<=C;i++)
            for(int j=0;j<=D && i*25+j*10<=C;j++)
                for(int k=0;k<=N && i*25+j*10+k*5<=C;k++)
                    for(int l=0;l<=P && i*25+j*10+k*5+l<=C;l++){
                        if(i*25+j*10+k*5+l==C){
                            if(i+j+k+l<best) best = i+j+k+l, q=i,d=j,n=k,p=l;
                        }
                    }
        if(best == INT_MAX) printf("Cannot dispense the desired amount.\n");
        else printf("Dispense %d quarters, %d dimes, %d nickels, and %d pennies.\n",q,d,n,p);
    }
    return 0;
}

Followed by:

Post your reply here:
User ID:
Password:
Title:

Content:

Home Page   Go Back  To top


All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator