Notice
Recent Posts
Recent Comments
«   2024/09   »
1 2 3 4 5 6 7
8 9 10 11 12 13 14
15 16 17 18 19 20 21
22 23 24 25 26 27 28
29 30
Archives
Today
Total
관리 메뉴

충분히 쌓여가는

백준[Java] 2480번 주사위 세개 본문

IT/Java[백준]

백준[Java] 2480번 주사위 세개

빌드이너프 2023. 2. 15. 10:39

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

 

2480번: 주사위 세개

1에서부터 6까지의 눈을 가진 3개의 주사위를 던져서 다음과 같은 규칙에 따라 상금을 받는 게임이 있다.  같은 눈이 3개가 나오면 10,000원+(같은 눈)×1,000원의 상금을 받게 된다.  같은 눈이 2개

www.acmicpc.net


문제풀이 1

import java.util.Scanner;
public class _2480_1 {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);

        int a = sc.nextInt();
        int b = sc.nextInt();
        int c = sc.nextInt();

        // 변수가 모두 다른 경우
        if (a != b && a != c && b != c) {
            int max;
            // a > b
            if (a > b) {
                // c > a > b
                if (c > a) {
                    max = c;
                }
                // a > b, c
                else {
                    max = a;
                }
            }
            // b > a
            else {
                // c > b > a
                if (c > b) {
                    max = c;
                }
                // b > a, c
                else {
                    max = b;
                }
            }
            System.out.println(max * 100);
        }

        // 적어도 한 쌍 이상의 서로 같은 변수 존재
        else {
            // 3개의 변수가 같음
            if (a == b && a == c) {
                System.out.println(10000 + a * 1000);
            }
            else {
                // a가 b 혹은 c와 같은 경우
                if (a == b || a == c) {
                    System.out.println(1000 + a * 100);
                }
                // b가 c랑 다른 경우
                else {
                    System.out.println(1000 + b * 100);
                }
            }
        }
    }
}

문제풀이 2

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.StringTokenizer;

public class _2480_2 {
    public static void main(String[] args) throws IOException {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        StringTokenizer 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 && b != c) {
            int max;
            // a > b
            if (a > b) {
                // c > a > b
                if (c > a) {
                    max = c;
                }
                // a > b, c
                else {
                    max = a;
                }
            }
            // b > a
            else {
                // c > b > a
                if (c > b) {
                    max = c;
                }
                // b > a, c
                else {
                    max = b;
                }
            }
            System.out.println(max * 100);
        }

        // 적어도 한 쌍 이상의 서로 같은 변수 존재
        else {
            // 3개의 변수가 같음
            if (a == b && a == c) {
                System.out.println(10000 + a * 1000);
            }
            else {
                // a가 b 혹은 c와 같은 경우
                if (a == b || a == c) {
                    System.out.println(1000 + a * 100);
                }
                // b가 c랑 다른 경우
                else {
                    System.out.println(1000 + b * 100);
                }
            }
        }
    }
}

문제풀이 3

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

public class _2480_3 {
    public static void main(String[] args) throws IOException {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        String[] str = br.readLine().split(" ");

        int a = Integer.parseInt(str[0]);
        int b = Integer.parseInt(str[1]);
        int c = Integer.parseInt(str[2]);

        // 변수가 모두 다른 경우
        if (a != b && a != c && b != c) {
            int max;
            // a > b
            if (a > b) {
                // c > a > b
                if (c > a) {
                    max = c;
                }
                // a > b, c
                else {
                    max = a;
                }
            }
            // b > a
            else {
                // c > b > a
                if (c > b) {
                    max = c;
                }
                // b > a, c
                else {
                    max = b;
                }
            }
            System.out.println(max * 100);
        }

        // 적어도 한 쌍 이상의 서로 같은 변수 존재
        else {
            // 3개의 변수가 같음
            if (a == b && a == c) {
                System.out.println(10000 + a * 1000);
            }
            else {
                // a가 b 혹은 c와 같은 경우
                if (a == b || a == c) {
                    System.out.println(1000 + a * 100);
                }
                // b가 c랑 다른 경우
                else {
                    System.out.println(1000 + b * 100);
                }
            }
        }
    }
}

문제풀이 4

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.StringTokenizer;

public class _2480_4 {
    public static void main(String[] args) throws IOException {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        StringTokenizer 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 && b != c) {
            int max = Math.max(a, Math.max(b, c));
            System.out.println(max * 100);
        }
        // 3개의 변수가 모두 같은 경우
        else if (a == b && a ==c) {
            System.out.println(10000 + a * 1000);
        }
        // a가 b혹은 c와 같은 경우
        else if (a == b || a ==c) {
            System.out.println(1000 + a * 100);
        }
        // b와 c랑 같은 경우
        else {
        System.out.println(1000 + b * 100);
        }
    }
}

 

'IT > Java[백준]' 카테고리의 다른 글

백준[Java] 10950번 A+B-3  (0) 2023.02.15
백준[Java] 2739번 구구단  (0) 2023.02.15
백준[Java] 2525번 오븐 시계  (2) 2023.02.14
백준[Java] 2884번 알람 시계  (0) 2023.02.14
백준[Java] 14681번 사분면 고르기  (0) 2023.02.14