본문 바로가기

자바(JAVA)/자료구조 & 알고리즘

백준 2480 자바(JAVA) 주사위 세개

백준 2480 자바(JAVA) 주사위 세개 문제

 

 

문제는 세개의 주사위 값을 입력값을 받아

 

1) 모든 눈이 같은 경우

2) 같은 눈이 두개인 경우

3) 모든 눈이 다른 경우

 

세가지 조건에 따라 상금 값을 출력하는 문제이다.

 

 

백준 2480 자바(JAVA) 주사위 세개 문제 풀이

 

 

 

다른 좋은 풀이들도 있겠지만, 내가 푼 코드를 공유한다.

 

 

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

public class Main {

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

		StringTokenizer st = new StringTokenizer(str, " ");

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

		int money = 0;
		
		boolean x = A - B == 0;
		boolean y = B - C == 0;
		boolean z = C - A == 0;

		if (x && y && z) {

			money = 10000 + (A * 1000);

		} else if (x && !y && !z) {
			
			money = 1000 + (A * 100);
			
		} else if (!x && !y && z) {
			
			money = 1000 + (A * 100);
			
		} else if (!x && y && !z) {
			
			money = 1000 + (B * 100);
			
		} else if (!x && !y && !z) {
			
			int max = 0;
			
			if (A > B && A > C) {
				
				max = A;
				
			} else if (B > A && B > C) {
				
				max = B;
				
			} else {
				
				max = C;
				
			}
			
			money = max * 100;
			
		}

		System.out.println(money);
	}
}