본문 바로가기
Beakjoon&프로그래머스/Java

[백준/Java] 6811번 Old Fishin’ Hole

by 현장 2026. 2. 6.

-Code

import java.io.*;
import java.util.*;

public class BOJ6811 {
    public static void main(String[] args) throws IOException {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));

        int troutPoint = Integer.parseInt(br.readLine());
        int pikePoint = Integer.parseInt(br.readLine());
        int pickerelPoint = Integer.parseInt(br.readLine());
        int limit = Integer.parseInt(br.readLine());

        // 3개 종류만 있으므로 3중 for문
        int cnt = 0;
        for (int troutCnt = 0; troutCnt <= (limit / troutPoint); troutCnt++) {
            for (int pikeCnt = 0; pikeCnt <= (limit / pikePoint); pikeCnt++) {
                for (int pickerelCnt = 0; pickerelCnt <= (limit / pickerelPoint); pickerelCnt++) {
                    int sum = (troutPoint * troutCnt) + (pikePoint * pikeCnt) + (pickerelPoint * pickerelCnt);
                    // 제한 이하고 1개 이상 물고기를 잡은 경우
                    if (sum <= limit && (troutCnt + pikeCnt + pickerelCnt) > 0) {
                        System.out.println(
                                String.format(
                                        "%d Brown Trout, %d Northern Pike, %d Yellow Pickerel"
                                        , troutCnt, pikeCnt, pickerelCnt
                                )
                        );
                        cnt++;
                    }
                }
            }
        }
        System.out.println("Number of ways to catch fish: " + cnt);
        br.close();
    }
}

'Beakjoon&프로그래머스 > Java' 카테고리의 다른 글

[백준/Java] 14500번 테트로미노  (0) 2026.02.07
[백준/Java] 2660번 회장뽑기  (0) 2026.02.06
[백준/Java] 16953번 A → B  (0) 2026.02.05
[백준/Java] 9019번 DSLR  (0) 2026.02.05
[백준/Java] 34845번 강의평  (0) 2026.02.05