- 난이도: 브론즈 2
- 알고리즘: 그리디 알고리즘
500보다 크거나 같으면 카운트 증가시키고 500 줄이고, 100보다 크거나 같으면 카운트 증가시키고 100 줄이고... 를 0이 될때까지 줄여나가면서 반복하면 된다.
#include <iostream>
#include <string>
#include <vector>
using namespace std;
int main() {
int x;
cin >> x;
x = 1000 - x;
int cnt = 0;
while (x >= 500) {
x -= 500;
cnt++;
}
while (x >= 100) {
x -= 100;
cnt++;
}
while (x >= 50) {
x -= 50;
cnt++;
}
while (x >= 10) {
x -= 10;
cnt++;
}
while (x >= 5) {
x -= 5;
cnt++;
}
while (x >= 1) {
x -= 1;
cnt++;
}
cout << cnt;
}