[BaekJoon] 5585 거스름돈 (Java)

SeongWon Oh·2021년 10월 14일
0
post-thumbnail

🔗 문제 링크

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


👨🏻‍💻 작성한 코드

import java.util.*;
import java.io.*;

public class Main {

	public static void main(String[] args) throws Exception {
		// TODO Auto-generated method stub
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		int[] moneyList = {500, 100, 50, 10, 5, 1};
		int remain = 0;
		int totalCoin = 0;
		
		int money = Integer.parseInt(br.readLine());
		remain = 1000 - money;
		
		int index = 0;
		while (remain != 0) {
			totalCoin += (remain/moneyList[index]);
			remain %= moneyList[index];
			index++;
			
		}
		
		System.out.println(totalCoin);
	}

}
profile
블로그 이전했습니다. -> https://seongwon.dev/

1개의 댓글

comment-user-thumbnail
2021년 10월 15일

나도 어제 그리디로 이 문제 풀었는데 js 화나네

답글 달기