Problem D: How many banknotes
Time Limit: 1 Sec Memory Limit: 2 MBSubmit: 11725 Solved: 6865
[ Submit ][ Status ][ Web Board ]
Description
When customers go to the store to buy things, bills up to $100 like to be paid in cash. Stores like to pay customers their change with the least amount of banknotes. Please write a program to help the store calculate how many $20, $10, $5, and $1 bills the store should pay the customer when he buys x dollars and gives a $100 bill so that the bills Minimum total. Assuming that no other denominations exist, nor do they cost a few cents, there are always enough banknotes in stores.
Input
Enter an integer x, 0<x<100.
Output
Outputs the number of bills in denominations of $20, $10, $5, and $1 in order. See sample for output format.
Sample Input
Sample Output
HINT
When you can pay a large denomination banknote, do not pay a smaller denomination banknote, in order to meet the minimum total number of banknotes, pay attention to the control of the scanf() format.
Append Code
#include <stdio.h>
#include <stdlib.h>
int
main()
{
int
x,a,b,c,d,e,f,g,h;
scanf
(
"%d"
,&x,&a,&b,&c,&d);
e=(100-x)/20;
f=(100-x-20*e)/10;
g=(100-x-20*e-10*f)/5;
h=100-x-20*e-10*f-5*g;
printf
(
"$20 bills: %d\n"
,e);
printf
(
"$10 bills: %d\n"
,f);
printf
(
" $5 bills: %d\n"
,g);
printf
(
" $1 bills: %d\n"
,h);
return
0;
}