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

JINI·2022년 12월 20일
0

✔️2480.

- 문제.주사위 세개

📕풀이1.

import java.util.Scanner;
	public class Main {
		public static void main(String args[]){
			Scanner input = new Scanner(System.in);
			int a= input.nextInt();
			int b= input.nextInt();
			int c = input.nextInt();

			if(a==b && b==c && a==c) {
				System.out.println(10000 + (a*1000));

			}else if(a==b || a==c) {
				System.out.println(1000+(a*100));
			}else if(b==c){
				System.out.println(1000+(b*100));
			}else {
				System.out.println(Math.max(a, Math.max(b, c))*100);
			}
		}
	}

Math.max()는 두 인자 값 중 큰 값을 리턴하는 함수로
이 메서드를 사용해서 풀이했다.

✍️같은 눈이 3개가 나오면 10,000원+(같은 눈)×1,000원의 상금
모두 같은 눈이 나올 경우는 &&를 이용해 한 줄에 작성했다.

✍️같은 눈이 2개만 나오는 경우에는 1,000원+(같은 눈)×100원의 상금
같은 눈 2개는 a의 주사위가 b나 c와 같을 경우와 b가 c와 같아 a와는 다를 경우이다.

✍️모두 다른 눈이 나오는 경우에는 (그 중 가장 큰 눈)×100원의 상금
모든 다른 눈은 Math.max() 메서드를 사용해서 가장 큰 값을 구해서 계산해준다.


📕풀이2.

import java.util.Scanner;
	public class Main {
		public static void main(String args[]){
			Scanner input = new Scanner(System.in);
			int a= input.nextInt();
			int b= input.nextInt();
			int c = input.nextInt();

			if(a==b && a==c) {
				System.out.println(10000 + (a*1000));

			}else if(a==b&&a!=c || a==c&&a!=b) {
				System.out.println(1000+(a*100));
			}else if(b==c&&b!=a){
				System.out.println(1000+(b*100));
			}else {
				int max=a;
				if(max<b)
					max=b;
				if(max<c)
					max=c;
				System.out.println(max*100);
			}
		}
	}
profile
꾸준히 성장하는 개발자

0개의 댓글