BUPT-homework/pset9/5-greedy.c
2021-11-25 16:13:12 +08:00

33 lines
485 B
C

#include <stdio.h>
int getCash(int n);
int main(void) {
int n;
scanf("%d", &n);
getCash(n);
return 0;
}
int getCash(int n) {
int cashes[7] = {};
int cash_rep[7] = {100, 50, 20, 10, 5, 2, 1};
while (n) {
for (int i = 0; i < 7; i++) {
if (n >= cash_rep[i]) {
n -= cash_rep[i];
cashes[i]++;
break;
}
}
}
for (int i = 0; i < 7; i++) {
if (cashes[i])
printf("%d:%d\n", cash_rep[i], cashes[i]);
}
return 1;
}