이 문제는 굉장히 쉬운편이었습니다...
그냥 다중 if문으로 해도 해결이 되는 쉬운 문제였어요.
N으로 주어진 수를 1000에서 빼고 뺼 수 있는 수를 차례대로 빼면 완성이됩니다.
public class Main {
private static int N,res;
public static void main(String[] args) throws IOException{
BufferedReader br= new BufferedReader(new InputStreamReader(System.in));
N = Integer.parseInt(br.readLine());
res = 0;
N = 1000-N;
while(N != 0) {
if(N>=500) {
res++;
N = N-500;
}else if(N>=100) {
res++;
N = N-100;
}else if(N >=50) {
res++;
N = N-50;
}else if(N>=10) {
res++;
N = N-10;
}else if(N>=5) {
res++;
N = N-5;
}else {
res++;
N = N-1;
}
}
System.out.println(res);
}
}
'개발 > 알고리즘' 카테고리의 다른 글
백준 2156 다이나믹프로그래밍 (0) | 2021.03.21 |
---|---|
백준 알고리즘 2217 (0) | 2021.02.28 |
백준 1931 그리디 알고리즘 (0) | 2021.02.25 |
백준 11047번 그리디 알고리즘 (0) | 2021.02.23 |
백준 알고리즘 그리디알고리즘 11399번 (0) | 2021.02.21 |