AcWing 653. 钞票
原题链接
中等
作者:
王小强
,
2021-02-18 15:21:21
,
所有人可见
,
阅读 274
用到了贪心的思想,所有这在语法题里算中等难度了!
// Greedy Solution
#include <iostream>
using namespace std;
int n;
int denominations[] {1, 2, 5, 10, 20, 50, 100};
int counts[7];
int main(void) {
scanf("%d", &n);
const int x = n;
for (int i = 6; i >= 0; --i) {
while (n >= denominations[i]) {
n -= denominations[i];
++counts[i];
}
}
printf("%d\n", x);
for (int i = 6; i >= 0; --i)
printf("%d nota(s) de R$ %d,00\n", counts[i], denominations[i]);
return 0;
}