[BAEKJOON] 조건문 2480번 - 주사위 세 개

밍챠코·2024년 3월 17일
0

BAEKJOON

목록 보기
18/38

📝[2480]

[Java]

1. Scanner 이용

import java.util.Scanner;

public class Main{
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        
        int a, b, c;
        a = sc.nextInt();
        b = sc.nextInt();
        c = sc.nextInt();
        
        if(a == b && a == c){ //세 개의 눈이 모두 같은 경우
            System.out.print(10000 + a * 1000);
        } else if(a == b || a == c){ //a와 b 혹은 c의 눈이 같은 경우
            System.out.print(1000 + a * 100);
        } else if(b == c){ //b와 c의 눈이 같은 경우
            System.out.print(1000 + b * 100);
        } else{ //세 개의 눈이 모두 다른 경우
            int max = Math.max(a, Math.max(b, c));
            System.out.print(max * 100);
        }
        sc.close();
    }
}

2. BufferedReader 이용

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

public class Main{
    public static void main(String[] args) throws IOException{
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        StringTokenizer st = new StringTokenizer(br.readLine(), " ");
        
        int a, b, c;
        a = Integer.parseInt(st.nextToken());
        b = Integer.parseInt(st.nextToken());
        c = Integer.parseInt(st.nextToken());
        
        //세 개의 눈이 모두 다른 경우
        if(a!=b && b!=c && a!=c){
            int max = Math.max(a, Math.max(b, c));
            System.out.print(max * 100);
        }
        //세 개의 눈이 모두 같은 경우
        else if(a == b && a == c){ 
            System.out.print(10000 + a * 1000);
        }
        //a가 b 혹은 c랑 같은 경우
        else if(a == b || a == c){
            System.out.print(1000 + a * 100);
        } 
        else{ //b랑 c가 같은 경우
            System.out.print(1000 + b * 100);
        }
        
        br.close();
    }
}

Math.max(a,b) : 두 개의 인자 a와 b를 비교하여 최댓값 출력


[Javascript]

const [a, b, c] = require('fs').readFileSync('/dev/stdin').toString().trim().split(" ").map(Number);

if(a === b && a === c){
    console.log(10000 + a * 1000);
} else if(a === b || a === c){
    console.log(1000 + a * 100);
} else if(b === c){
    console.log(1000 + b * 100);
} else{
    console.log(Math.max(a, b, c) * 100);
}

Math.max(value1, value2, ..., valueN)
: 입력값으로 받은 0개 이상의 숫자 중 가장 큰 숫자를 반환하는 함수


[Python]

a, b, c = map(int, input().split())

if a==b and a==c :
    print(10000 + a * 1000)
elif a==b or a==c :
    print(1000 + a * 100)
elif b==c :
    print(1000 + b * 100)
else :
    print(max(a, max(b, c)) * 100)
    """
    max = max(a, max(b, c))  
    print(max * 100)
    """

0개의 댓글