A. Hit the Lottery
Allen has a LOT of money. He has dollars in the bank. For security reasons, hwants to withdraw it in cash (we will not disclose the reasons here). The denominations for dollar bills are
, , , , . What is the minimum number of bills Allen could receive after withdrawing his entire balance?
The first and only line of input contains a single integer ().
Output the minimum number of bills that Allen could receive.
125
3
43
5
1000000000
10000000
In the first sample case, Allen can withdraw this with a dollar bill, a dollar bill, and a dollar bill. There is no way for Allen to receive dollars in one or two bills.
In the second sample case, Allen can withdraw two dollar bills and three dollar bills.
In the third sample case, Allen can withdraw (ten million!) dollar bills.
---------------------------------------------------------------------------------------------------------------
solution:
---------------------------------------------------------------------------------------------------------------
#include<iostream>
using namespace std;
int main()
{
int amount, note100, note20, note10, note5, note1;
note100 = note20 = note10 = note5 = note1 = 0;
cin >> amount;
if (amount >= 100)
{
note100 = amount / 100;
amount -= note100 * 100;
}
if (amount >= 20)
{
note20 = amount / 20;
amount -= note20 * 20;
}
if (amount >= 10)
{
note10 = amount / 10;
amount -= note10 * 10;
}
if (amount >= 5)
{
note5 = amount / 5;
amount -= note5 * 5;
}
if (amount >= 1)
{
note1 = amount;
}
cout << (note100 + note20 + note10 + note5 + note1) << endl;
return 0;
}
No comments:
Post a Comment