๋ณธ๋ฌธ ๋ฐ”๋กœ๊ฐ€๊ธฐ
โœจ Algorithm

[๋ฐฑ์ค€/C++] 5585๋ฒˆ : ๊ฑฐ์Šค๋ฆ„๋ˆ

by nitronium102 2021. 8. 15.

๋ฌธ์ œ

ํƒ€๋กœ๋Š” ์ž์ฃผ JOI์žกํ™”์ ์—์„œ ๋ฌผ๊ฑด์„ ์‚ฐ๋‹ค. JOI์žกํ™”์ ์—๋Š” ์ž”๋ˆ์œผ๋กœ 500์—”, 100์—”, 50์—”, 10์—”, 5์—”, 1์—”์ด ์ถฉ๋ถ„ํžˆ ์žˆ๊ณ , ์–ธ์ œ๋‚˜ ๊ฑฐ์Šค๋ฆ„๋ˆ ๊ฐœ์ˆ˜๊ฐ€ ๊ฐ€์žฅ ์ ๊ฒŒ ์ž”๋ˆ์„ ์ค€๋‹ค. ํƒ€๋กœ๊ฐ€ JOI์žกํ™”์ ์—์„œ ๋ฌผ๊ฑด์„ ์‚ฌ๊ณ  ์นด์šดํ„ฐ์—์„œ 1000์—” ์ง€ํ๋ฅผ ํ•œ์žฅ ๋ƒˆ์„ ๋•Œ, ๋ฐ›์„ ์ž”๋ˆ์— ํฌํ•จ๋œ ์ž”๋ˆ์˜ ๊ฐœ์ˆ˜๋ฅผ ๊ตฌํ•˜๋Š” ํ”„๋กœ๊ทธ๋žจ์„ ์ž‘์„ฑํ•˜์‹œ์˜ค.

์ž…๋ ฅ

์ž…๋ ฅ์€ ํ•œ์ค„๋กœ ์ด๋ฃจ์–ด์ ธ์žˆ๊ณ , ํƒ€๋กœ๊ฐ€ ์ง€๋ถˆํ•  ๋ˆ(1 ์ด์ƒ 1000๋ฏธ๋งŒ์˜ ์ •์ˆ˜) 1๊ฐœ๊ฐ€ ์“ฐ์—ฌ์ ธ์žˆ๋‹ค.

์ถœ๋ ฅ

์ œ์ถœํ•  ์ถœ๋ ฅ ํŒŒ์ผ์€ 1ํ–‰์œผ๋กœ๋งŒ ๋˜์–ด ์žˆ๋‹ค. ์ž”๋ˆ์— ํฌํ•จ๋œ ๋งค์ˆ˜๋ฅผ ์ถœ๋ ฅํ•˜์‹œ์˜ค.

ํ’€์ด

// ๊ฑฐ์Šค๋ฆ„๋ˆ
#include <iostream>
using namespace std;

int main(){
  int money, cnt=0;
  cin >> money;

  money = 1000-money;
  int change[] = {500, 100, 50, 10, 5, 1};
  for (int i=0; i<6; i++){
    if (money < change[i])
      continue;
    cnt += money/change[i];
    money %= change[i];
  }

  cout << cnt;
}

๋Œ“๊ธ€