• 문제 링크
27106번: Making Change
Given the amount of a purchase (1 ≤ P ≤ 99) in cents, determine the way to make "change for a dollar" for that purchase. Use four standard US coin denominations: 1, 5, 10, and 25. The way to make change uses the least number coins.
www.acmicpc.net
• 풀이 코드
import java.io.BufferedWriter;
import java.io.IOException;
import java.io.OutputStreamWriter;
public class Main {
public static void main(String[] args) throws IOException {
BufferedWriter bw = new BufferedWriter(new OutputStreamWriter(System.out));
StringBuilder sb = new StringBuilder();
int p = 100 - read();
sb.append(p / 25).append(" ").append((p %= 25) / 10).append(" ").append((p %= 10) / 5).append(" ").append(p % 5);
bw.write(sb.toString());
bw.flush();
}
private static int read() throws IOException {
int c, n = System.in.read() & 15;
while ((c = System.in.read()) > 32) n = (n << 3) + (n << 1) + (c & 15);
return n;
}
}
'Problem Solving > Baekjoon' 카테고리의 다른 글
[백준] 21146 Rating Problems - Greedy / Java (0) | 2024.04.13 |
---|---|
[백준] 15001 Frog Leaps - Greedy / Java (0) | 2024.04.12 |
[백준] 3578 Holes - Greedy / Java (0) | 2024.04.10 |
[백준] 5992 The Leisurely Stroll - Graph Theory / Java (0) | 2024.04.09 |
[백준] 9790 Elephant Show - Graph Theory / Java (0) | 2024.04.08 |
댓글