알고리즘 도전기 - 4

김치전사·2022년 3월 11일
0

알고리즘 도전기

목록 보기
4/89

2480 주사위 세개

문제

1에서부터 6까지의 눈을 가진 3개의 주사위를 던져서 다음과 같은 규칙에 따라 상금을 받는 게임이 있다.
1. 같은 눈이 3개가 나오면 10,000원+(같은 눈)×1,000원의 상금을 받게 된다.
2. 같은 눈이 2개만 나오는 경우에는 1,000원+(같은 눈)×100원의 상금을 받게 된다.
3. 모두 다른 눈이 나오는 경우에는 (그 중 가장 큰 눈)×100원의 상금을 받게 된다.
예를 들어, 3개의 눈 3, 3, 6이 주어지면 상금은 1,000+3×100으로 계산되어 1,300원을 받게 된다. 또 3개의 눈이 2, 2, 2로 주어지면 10,000+2×1,000 으로 계산되어 12,000원을 받게 된다. 3개의 눈이 6, 2, 5로 주어지면 그중 가장 큰 값이 6이므로 6×100으로 계산되어 600원을 상금으로 받게 된다.
3개 주사위의 나온 눈이 주어질 때, 상금을 계산하는 프로그램을 작성 하시오.

입력

첫째 줄에 3개의 눈이 빈칸을 사이에 두고 각각 주어진다.

출력

첫째 줄에 게임의 상금을 출력 한다.

예제 입력

3 3 6

예제 출력

1300

코드

import java.util.*;

public class Main{
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        int firstDice = scanner.nextInt();
        int secondDice = scanner.nextInt();
        int thirdDice = scanner.nextInt();
        System.out.println(calculDice(firstDice,secondDice,thirdDice));
    }
    public static int calculDice(int firstDice, int secondDice, int thirdDice){
        int result=0;
        if(firstDice==secondDice&&firstDice==thirdDice){
            return 10000+firstDice*1000;
        }else if(firstDice==secondDice&&firstDice!=thirdDice){
            return 1000+firstDice*100;
        }else if(firstDice==thirdDice&&firstDice!=secondDice){
            return 1000+firstDice*100;
        }else if(firstDice!=secondDice&&secondDice==thirdDice){
            return 1000+secondDice*100;
        }else if(firstDice!=secondDice&&firstDice!=thirdDice&&secondDice!=thirdDice){
            int tmp = firstDice;
            if(tmp<secondDice){
                tmp=secondDice;
            }
            if(tmp<thirdDice){
                tmp=thirdDice;
            }
            return tmp*100;
        }
        return result;
    }
}
profile
개인공부 블로그입니다. 상업적 용도 X

0개의 댓글