본문 바로가기

Algorithm

(C++) - 백준(BOJ) 5585번:거스름돈 답

반응형
#include <iostream>
using namespace std;
int main() {
    int num,cnt=0;
    cin >> num;
    num = 1000 - num;
    while (num >= 500)
    {
        cnt += num / 500;
        num %= 500;
    }
    while (num >= 100)
    {
        cnt += num / 100;
        num %= 100;
    }
    while (num >= 50)
    {
        cnt += num / 50;
        num %= 50;
    }
    while (num >= 10)
    {
        cnt += num / 10;
        num %= 10;
    }
    while (num >= 5)
    {
        cnt += num / 5;
        num %= 5;
    }
    while (num >= 1)
    {
        cnt += num / 1;
        num %= 1;
    }
    cout << cnt << '\n';
}​