-
[Baekjoon Online Judge] 2839번: 설탕 배달문제 풀이/Baekjoon Online Judge 2020. 12. 23. 18:01
2839번: 설탕 배달
import java.io.*; public class Baekjoon2839 { public static int count(int weight) { int length = weight / 3; for (int i = 0; i <= length; i++) { for (int j = 0; j <= length; j++) { if (weight == i * 3 + j * 5) { // 가장 먼저 알맞게 계산된 설탕 봉지의 개수를 반환한다. return i + j; } } } return -1; } public static void main(String[] args) throws IOException { BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(System.in)); BufferedWriter bufferedWriter = new BufferedWriter(new OutputStreamWriter(System.out)); int weight = Integer.parseInt(bufferedReader.readLine()); // 설탕 무게 int count = count(weight); bufferedWriter.write(String.valueOf(count)); bufferedWriter.flush(); bufferedReader.close(); bufferedWriter.close(); } }
'문제 풀이 > Baekjoon Online Judge' 카테고리의 다른 글
[Baekjoon Online Judge] 2217번: 로프 (0) 2020.12.26 [Baekjoon Online Judge] 5585번: 거스름돈 (0) 2020.12.26 [Baekjoon Online Judge] 1931번: 회의실배정 (0) 2020.12.25 [Baekjoon Online Judge] 11047번: 동전 0 (0) 2020.12.25 [Baekjoon Online Judge] 11399번: ATM (0) 2020.12.23