[백준] 11047 동전 0

leeng·2023년 8월 2일
0
public class CountCoin {
    public static void main(String[] args) {
        int n = 10;
        int k = 4200;
        String input = "1\n" +
                "5\n" +
                "10\n" +
                "50\n" +
                "100\n" +
                "500\n" +
                "1000\n" +
                "5000\n" +
                "10000\n" +
                "50000";
    }

    int count(int n, int k, String input) {
        int result = -1;

        int[] coinValues = new int[n];
        coinValues = Arrays.stream(input.split("\n")).mapToInt(Integer::parseInt).toArray();

        int count = 0;

        while (k > 0) {
            for (int i = n - 1; i >= 0; i--) {
                if (k >= coinValues[i]) {
                    count += k / coinValues[i];
                    k %= coinValues[i];
                }
            }
        }

        System.out.println(k);
        System.out.println(count);
        result = count;

        return result;
    }
}
profile
기술블로그보다는 기록블로그

0개의 댓글