새소식

반응형
250x250
Baekjoon/Bronze

[백준] 조건문 - 2480_주사위 세 개 Java[자바]

  • -
728x90
반응형

[Bronze IV]

첫 번째 경우 : 세 가지의 숫자가 모두 동일할 때

if(f == s && s == t) {
	price = 10000 + f * 1000;
}

두 번째 경우 : 세 가지의 숫자가 모두 다를 때

이 때에는 Math.max()를 사용해서 최대값을 가져올 수 있다.

if(f != s && s != t && t != f) {
	int max = Math.max(f, Math.max(s, t));
    price = 100 * max;
}

마지막 경우 : 두 가지의 숫자만 같을 때로 나눌 수 있다.

if(f == s || f == t) {
	price = 1000 + 100 * f;
} else {
	price = 1000 + 100 * s;
}

전체 코드

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 = new StringTokenizer(br.readLine(), " ");
        
        int f = Integer.valueOf(st.nextToken());
        int s = Integer.valueOf(st.nextToken());
        int t = Integer.valueOf(st.nextToken());
        int price = 0;
        
        if(f == s && s == t) {
            price = 10000 + f * 1000;
        } else if(f != s && f != t && s != t) {
            int max = Math.max(f, Math.max(s, t));
            price = max * 100;
        } else {
            if(f == s || f == t) {
                price = 1000 + f * 100;
            } else {
                price = 1000 + s * 100;
            }
        }
        
        System.out.print(price);
    }
}

728x90
반응형
Contents

포스팅 주소를 복사했습니다

이 글이 도움이 되었다면 공감 부탁드립니다.