Donghua OJ title 87 basis wages slightly

Problem Description:
As a person needs for their families, is most looking forward to the day of the monthly pay day, Oh
but for the staff of the Treasury, this day is a very busy day, the Treasury mustaches recently in consider the question: If the amount of wages of each employee knows how many need to be prepared at least RMB, employees do not have to give change when the wages of each employee to do?
It is assumed that wages are positive integers, unit Yuan, a total of RMB 100 yuan, 50 yuan, 20 yuan, 10 yuan, 5 yuan, two yuan and 1 yuan seven kinds.

Input Explanation:
first inputs a T, T represents a group comprising the test data,
a first data line of each test is an integer n (n <100), represents the number of employees,
the second row of n wages.

Description Output:
For each set of test data outputs an integer x, denotes at least RMB sheets need to be prepared.
Each output per line, the first line with no extra spaces end of the line, no extra blank line before and after.

Entry:
. 3
. 1
299
2
299 197
. 5
1,234,567,891,012,345
Sample output:
. 8
14
186
summarizes
1. idea straighten it; still prefer dynamic memory allocation, heart clean "waste refuse."
2. Come on!

#include<stdio.h>
#include<stdlib.h>
int main(){
	int count;
	int i,j,T,n,sum;
	int *w;
	int a[7]={100,50,20,10,5,2,1};
	scanf("%d",&T);
	while(T--){
		scanf("%d",&n);
		w=(int *)malloc(sizeof(int)*n);
		for(i=0;i<n;i++){
			scanf("%d",&w[i]);
		}
		sum=0;
		for(j=0;j<n;j++){
			count=0;
			for(i=0;i<7 && w[j]>0;i++){
				if(w[j]>=a[i]){
					count+=w[j]/a[i];
					w[j]%=a[i];
				}
			}
			sum+=count;
		}
		printf("%d\n",sum);
	}
	return 0;
}


Published 22 original articles · won praise 1 · views 175

Guess you like

Origin blog.csdn.net/weixin_44205451/article/details/104618185