반응형
http://www.jungol.co.kr/bbs/board.php?bo_table=pbank&code=1183&sca=99
#include <stdio.h>
enum Coin { _500 = 0, _100, _50, _10, _5, _1, CM };
int W, myW, CoinNum[CM], AnsCoin[CM], CoinVal[CM] = {500, 100, 50, 10, 5, 1}, cnt;
void Print() {
for (int i = _500; i < CM; i++) cnt += AnsCoin[i];
printf("%d\n", cnt);
for (int i = _500; i < CM; i++)
printf("%d ", AnsCoin[i]);
printf("\n");
}
int main(void) {
//freopen("input.txt", "r", stdin);
scanf("%d", &W);
for (int i = 0; i < CM; i++) scanf("%d", &CoinNum[i]);
int gap;
while (W != myW) {
//printf("W: %d -> ", myW);
if (W > myW) {
for (int i = _1; i >= _500; i--)
if (CoinNum[i]) {
CoinNum[i]--, AnsCoin[i]++, myW += CoinVal[i];
break;
}
}
else {
gap = myW - W;
for (int i = _500; i < CM; i++)
if (gap >= CoinVal[i] && AnsCoin[i]) {
CoinNum[i]++, AnsCoin[i]--, myW -= CoinVal[i];
break;
}
}
//printf("%d\n", myW);
//Print();
}
Print();
return 0;
}
반응형
'프로그래밍 알고리즘' 카테고리의 다른 글
[정올 1239] 비밀편지 (0) | 2023.01.02 |
---|---|
[정올 1214] 히스토그램 (1) | 2022.12.31 |
[정올 1175] 주사위던지기2 (0) | 2022.12.31 |
[정올 1169] 주사위던지기1 (0) | 2022.12.31 |
[정올 1161] 하노이1 (0) | 2022.12.31 |