happy coding

[java] 5585. 거스름돈 본문

coding study/baekjoon

[java] 5585. 거스름돈

yeoonii 2023. 7. 28. 12:31
import java.io.*;
import java.lang.*;
import java.util.*;

public class Main {
    public static void main(String[] args) throws IOException {
        //타로가 지불할 돈 정수 입력 하나
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        int input = (1000 - Integer.parseInt(br.readLine()));

        int output = 0;
        int coins[] = {500, 100, 50, 10, 5, 1};

        for (int coin : coins) {
            output += (input/coin);
            input %= coin;
        }
        System.out.println(output);
    }
}

처음에 타로가 낼 돈의 지폐의 수(?)로 계산했다가, 주인이 거슬러주는 돈으로 바꿔서 풀었다. 굿

'coding study > baekjoon' 카테고리의 다른 글

[java] 2908. 상수  (0) 2023.07.28
[java] 2920.음계  (0) 2023.07.28
[java] 10093. 숫자  (0) 2023.07.28
[java] 10870. 피보나치 수 5  (0) 2023.07.28
[java] 10988. 팰린드롬인지 확인하기  (0) 2023.07.28
Comments