백준 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);
}
}
'자바(JAVA) > 자료구조 & 알고리즘' 카테고리의 다른 글
백준 10950번 자바(JAVA) BufferedReader 사용 (0) | 2023.05.06 |
---|---|
백준 2739번 자바(JAVA) 구구단 (0) | 2023.05.06 |
백준 2525번 자바(JAVA) 오븐 시계 (0) | 2023.05.06 |
백준 2884번 자바(JAVA) 알람시계 (0) | 2023.05.05 |
백준 14681 자바(JAVA) 사분면 - BufferedReader 입력 (0) | 2023.04.30 |