본문 바로가기

Programming/BaekJoon

[C++] 백준 5585번 : 거스름돈


https://www.acmicpc.net/problem/5585




#include <iostream>

using namespace std;

int main() {

cin.tie(NULL);

ios::sync_with_stdio(false);

int n;

cin >> n;

n = 1000 - n;


int cnt = 0;



while (n) {

if (n >= 500)

{

cnt++;

n = n - 500;

}

else if (n >= 100)

{

cnt++;

n = n - 100;

}

else if (n >= 50)

{

cnt++;

n = n - 50;

}

else if (n >= 10)

{

cnt++;

n = n - 10;

}

else if (n >= 5)

{

cnt++;

n = n - 5;

}

else

{

cnt++;

n = n - 1;

}

}


cout << cnt;

}