[Baekjoon 11047번] 동전 0 문제 (with 자바)

[Baekjoon 11047번] 동전 0 문제 (with 자바)

728x90

문제 11047번 - 동전 0 문제

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

풀이

package seohae.algorithm.level1; import java.io.BufferedWriter; import java.io.IOException; import java.io.OutputStreamWriter; import java.util.Scanner; import java.util.Stack; /** * https://www.acmicpc.net/problem/11047 */ public class Problem_012_11047 { public static void main(String[] args) throws IOException { Scanner sc = new Scanner(System.in); String param = sc.nextLine(); int num = Integer.parseInt(param.split(" ")[0]); int sum = Integer.parseInt(param.split(" ")[1]); Stack stack = new Stack(); /* 오름차순의 경우, 제일 비싼 동전부터 체크해야햐므로 stack 사용 */ for (int i = 0; i < num; i++) { Integer input = sc.nextInt(); stack.push(input); } int count = 0; /* 동전 개수 */ while (sum != 0) { int target = stack.pop(); count += sum / target; sum = sum % target; } System.out.println(count); } }

from http://devfunny.tistory.com/489 by ccl(A) rewrite - 2021-09-22 15:01:30