Problem Description
As a teacher Hang electricity, I am most looking forward to the day of the 8th month, because this day is pay day, feed their families depends on it, huh, huh
, but for school staff Treasury, this day is very busy day, the Treasury mustaches teacher recently considered a problem: If the amount of wages each teacher knows how many need to prepare a minimum of RMB in order in time to give every teacher wages of teachers do not give change it ?
It is assumed that teacher salaries are positive integers, unit Yuan, a total of RMB 100 yuan, 50 yuan, 10 yuan, 5 yuan, two yuan and 1 yuan six kinds.
Input
The number of input data comprising a plurality of test example, the first line of each test case is an integer n (n <100), represented by the teacher, and n is a teacher's salary.
n = 0 indicates the end of input, not treated.
Output
Each output a test case for the integer x, represents at least RMB sheets need to be prepared. Each output per line.
Sample Input
3 1 2 3 0
Sample Output
4
code show as below:
#include <bits/stdc++.h> using namespace std; int main(){ int money[6]={100,50,10,5,2,1}; int moneycount=sizeof(money)/sizeof(int); int n; int val; while(scanf("%d",&n)!=EOF,n){ int count=0; for(int i=0;i<n;i++){ cin>>val; for(int j=0;j<moneycount;j++){ if(val==0) break; count+=val/money[j]; val%=money[j]; } } printf("%d\n",count); } return 0; }