algorithms 백준 (BOJ)

(BOJ)백준 11047 (baekjoon 11047)

(BOJ)백준 11047 - 11047번: 동전 0

목차

11047번: 동전 0

코드

import java.io.*;

public class B11047 {
    static int n, k, a[] = new int[10], idx = 0;
    static String ins[];
    public static void main(String[] args) throws IOException {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        BufferedWriter bw = new BufferedWriter(new OutputStreamWriter(System.out));
        ins = br.readLine().split(" ");
        n = Integer.parseInt(ins[0]);
        k = Integer.parseInt(ins[1]);
        for (int i = 0; i < n; i++) {
            a[i] = Integer.parseInt(br.readLine());
            idx = (a[i] <= k) ? i : idx;
        }
        int count = 0;
        while (k != 0) {
            count += k / a[idx];
            k -= (k / a[idx]) * a[idx--];
        }
        bw.write(count + "\n");
        bw.flush();bw.close();

    }
}

설명