Hangzhou Electric Oj brush title (2021)

Wages slightly :)

Subject description:

As a teacher Hang electricity, is 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

By the answer:

#include<stdio.h>
//贪心算法 
int count(int n){                 
	int sum=0;
	int a[6]={100,50,10,5,2,1};     //人民币面值种类 
	for(int i=0;i<6;i++){
		sum+=n/a[i];                //人民币张数计算 
		n=n%a[i];
	} 
	return sum;
} 
int main() {
    int i,j,n;
    int a[100];
    while(scanf("%d",&n)!=EOF) {
    	int k=0;                  //注意! 
    	if(n==0)return 0;
        for(i=0; i<n; i++){
        	scanf("%d",&a[i]);
		}    
		for(j=0;j<n;j++){
		    k+=count(a[j]);	
		}
		printf("%d\n",k);
       	
    }
    return 0;
}

 

Published 55 original articles · won praise 0 · Views 1018

Guess you like

Origin blog.csdn.net/ZhangShaoYan111/article/details/104107146