카테고리 없음

9월 21일 목요일 TIL 회고록

tft4rollz 2023. 9. 22. 01:57

백준 2480번 주사위 세개


문제, 입력, 출력, 예제 입력

풀이

import java.util.Scanner;

public class Main {

  public static void main(String[] args) {

    Scanner sc = new Scanner(System.in);
    int one = sc.nextInt();
    int two = sc.nextInt();
    int three = sc.nextInt();
    int bigInt = 0;

    if (one > two && one > three) {
      bigInt = one;
    } else if (two > one && two > three) {
      bigInt = two;
    } else if (three > one && three > two) {
      bigInt = three;
    }

    if (one == two && two == three) {
      System.out.println(10000+one*1000);
    } else if (one == two && one != three) {
      System.out.println(1000+one*100);
    } else if (two == three && two != one) {
      System.out.println(1000+two*100);
    } else if (one == three && one != two) {
      System.out.println(1000+one*100);
    } else {
      System.out.println(bigInt * 100);
    }
  }
}

먼저 가장 큰 눈을 구하기 위해 if ~ else if문을 사용해 가장 큰 수를 bigInt에 넣었다.

그 후 if ~ else if 문을 사용해 같은 눈이 3개이면 (one == two && two == three) 10000원 + 같은 눈 * 1000원을 한 값을 출력했다.

one, two가 같고 one, three가 다르면 1000원 + one * 100원을 한 값을 출력했다. 

two, three가 같고 two, one이 다르면 1000원 + one * 100원을 한 값을 출력했다. 

one,three가 같고 one,two가 다르면 1000원 + one * 100원을 한 값을 출력했다. 

그 외에는 전부 다른 눈 이므로 가장 큰 수를 넣은 bigInt에 100을 곱한 값을 출력했다.