Description
As the teacher of hang-electric, the most hope of the day is 8th a month, because this day is the day of payday, the breadwinner depends on it, hehe, but for the staff of the school Finance Department, This day is a very busy day, the finance department's Mr. Hu has recently been thinking about a problem: if each teacher's salary is known, the minimum need to prepare how many yuan, in order to give each teacher pay when the teachers do not need to change it. This assumes that the teacher's salary is a positive integer, Unit yuan, a total of 100 yuan, 50 yuan, 10 yuan, 5 yuan, 2 yuan and 1 yuan six kinds of
input
input data contains multiple test instances, the first row of each test instance is an integer n (n <100), indicating the number of teachers, and then n a teacher's salary. N=0 represents the end of the input and does not handle
output
to output an integer x for each test instance that represents the minimum number of RMB to prepare. One row for each output
Sample Input
3
1 2 3
0
Sample Output
4
solution
Simple greed, it is obvious to spend as much as possible to make the number of RMB sheets prepared at least
Code
#include <cstdio> #include <iostream> using namespace std; int main () {int n;
while (scanf ("%d", &n), n) {int d,ans=0;
for (int i=0;i<n;i++) {scanf ("%d", &d);
ans+=d/100;d%=100;
ans+=d/50;d%=50;
ans+=d/10;d%=10;
ans+=d/5;d%=5;
ans+=d/2;d%=2;
Ans+=d;
printf ("%d\n", ans);
return 0; }