백준 단계별

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

pullwall 2023. 1. 3. 16:18
728x90
import java.util.*;

public class no2480 {
	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 && b!=c && a!=c) {
			int max;
			if(a>b) {
				if(c>a) { //c>a>b
					max=c;
				}
				else { //a
					max=a;
				}
			}
			else { //b>a
				if(c>b) { //c>b>a
					max=c;
				}
				else {
					max=b;
				}
			}
			System.out.println(max*100);
		}
		else {
			if(a==b&&a==c) { //a=b=c
				System.out.println(10000+a*1000);
			}
			else {
				if(a==b||a==c) { //a=b 혹은 a=c
					System.out.println(1000+a*100);
				}
				else { //b=c
					System.out.println(1000+b*100);
				}
			}
		}
	}
}

조건문에서 가장 먼저 처리해야 할 것은 케이스가 제일 많은 경우이다.

따라서 a, b, c모두 다를 경우를 먼저 처리해 주었고 나머지를 처리해 주었다.

 

최댓값 구하는 알고리즘도 이 문제를 통하여 공부하였다.

 

자세한 알고리즘은 코드 참조

728x90