fjnu 1195 Making Change

Description

In the old days before everything was electronic, you could pay for stuff with cash and (maybe) get change back. The number of coins you get could vary. For example, 10 cents in change can be done with 1 dime, or 2 nickels, or 1 nickel and 5 pennies, or 10 pennies. The rule of thumb was for the cashier to give the least amount of coins from the selection of coins in the register. Now since the cashiers may not be quick enough to give you the coins, you're to write a program that produces the correct amount of change in the fewest coins

Input

Each line of input will have 5 integers on it. The first number is the amount of change to make. The second number is the number of pennies available, followed by the number of nickels, then the number of dimes and finally the number of quarters.

Output

For each input, print a line that has the number of pennies, the number of nickels, the number of dimes and the number of quarters needed to make the given change using the least number of coins. If the requested amount of change can't be made from the given amount of coins, then print the message "Not enough change".

Sample Input

89 3 0 1 2 
89 10 10 10 10 
89 0 0 0 4
45 45 0 0 0 

Sample Output

Not enough change 
4 0 1 3
Not enough change
45 0 0 0

 

KEY:这题考的就是贪心,很典型的,由面值大的,开始“找钱”;

 

Source:

#include
< iostream >
using   namespace  std;

struct  node
{
    
int pennie;
    
int nickel;
    
int dime;
    
int quarter;
}
;

node a;
node b;

int  count( int  s)
{
    
while(a.quarter!=0&&s>=25)
    
{
        s
-=25;
        a.quarter
--;
        b.quarter
++;
    }

    
while(a.dime!=0&&s>=10
    
{
        s
-=10;
        a.dime
--;
        b.dime
++;
    }

    
while(a.nickel!=0&&s>=5)
    
{
        s
-=5;
        a.nickel
--;
        b.nickel
++;
    }
    
    
while(a.pennie!=0&&s>=1)
    
{
        s
-=1;
        a.pennie
--;
        b.pennie
++;
    }

    
return s;
}


int  main()
{
//    freopen("fjnu_1195.in","r",stdin);
    int s;
    
while(cin>>s>>a.pennie>>a.nickel>>a.dime>>a.quarter)
    
{
        b.pennie
=b.nickel=b.dime=b.quarter=0;
        s
=count(s);
        
if(s==0) cout<<b.pennie<<" "<<b.nickel<<" "<<b.dime<<" "<<b.quarter<<endl;
        
else cout<<"Not enough change"<<endl;
    }

    
return 0;
}










 
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值