[HDU] [2021] Paying Salaries :)

Problem Description

Loading...

Problem Analysis

Divide in a loop by the largest denomination available
and record the number of times

cpp
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
#include<stdio.h>
int main() {
	int n;
	while(scanf("%d",&n),n) {
		int sum=0;
		for(int i=0; i<n; i++) {
			int t;
			scanf("%d",&t);
			while(t>=100) {
				sum+=t/100;
				t%=100;
			}
			while(t>=50) {
				sum+=t/50;
				t%=50;
			}
			while(t>=10) {
				sum+=t/10;
				t%=10;
			}
			while(t>=5) {
				sum+=t/5;
				t%=5;
			}
			while(t>=2) {
				sum+=t/2;
				t%=2;
			}
			while(t>=1) {
				sum+=t/1;
				t%=1;
			}
		}
		printf("%d\n",sum);
	}
	return 0;
}

Problem address: HDU 2021: Payday :)))

This post is licensed under CC BY-NC-SA 4.0. If it helped, or if you have anything to say, the comment box below is open.
Page views —
Unique visitors —

Loading...