본문 바로가기
코딩테스트 준비/백준

[백준] 2476번 - 주사위 게임 [Java]

by mwzz6 2024. 12. 30.

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

 

[백준] 2476번 - 주사위 게임 [Java]
[백준] 2476번 - 주사위 게임 [Java]


1.  아이디어

 

if - else if - else 조건문을 활용하면 간단하게 해결할 수 있다.


2. 문제풀이

 

조건 1, 2, 3 순서로 체크해서 상금을 구했다.


3. 코드

 

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

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

        int N = Integer.parseInt(br.readLine());
        int max = 0;

        for (int i = 0; i < N; i++) {
            st = new StringTokenizer(br.readLine());

            int A = Integer.parseInt(st.nextToken());
            int B = Integer.parseInt(st.nextToken());
            int C = Integer.parseInt(st.nextToken());

            if (A == B && A == C) max = Math.max(max, 10000 + 1000 * A);
            else if (A == B) max = Math.max(max, 1000 + 100 * A);
            else if (B == C) max = Math.max(max, 1000 + 100 * B);
            else if (C == A) max = Math.max(max, 1000 + 100 * C);
            else max = Math.max(max, 100 * Math.max(A, Math.max(B, C)));
        }

        System.out.println(max);
    }
}

4. 후기