[백준/자바] 2480 주사위 세개
2022. 7. 5. 12:07ㆍ내가 보려고 만든 공부정리/백준
1. 내가 작성한 풀이(정답)
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int a = sc.nextInt();
int b = sc.nextInt();
int c = sc.nextInt();
int max = 0;
if(a == b && b == c) {
System.out.println(10000 + a*1000);
}else if(a != b && b != c && a != c) {
if(a > b && a > c) {
max = a;
}else if(b>a && b>c) {
max = b;
}else if(c>a && c>b) {
max = c;
}
System.out.println(max*100);
}else {
if(a == b) {
System.out.println(1000 + a*100);
}else if(a == c) {
System.out.println(1000 + a*100);
}else if(b == c) {
System.out.println(1000 + b*100);
}
}
}
}
처음에 max를 초기화시키지 않아 컴파일 에러가 났었다.
2. 모범 답안 예시
import java.io.*;
import java.util.*;
public class Main {
public static void main(String[] args) throws IOException {
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
StringTokenizer st = new StringTokenizer(br.readLine());
int a = Integer.parseInt(st.nextToken());
int b = Integer.parseInt(st.nextToken());
int c = Integer.parseInt(st.nextToken());
if (a == b && a == c) {
System.out.print(10000+a*1000);
} else if (a == b) {
System.out.print(1000+a*100);
} else if (a == c) {
System.out.print(1000+a*100);
} else if (b == c) {
System.out.print(1000+b*100);
} else {
System.out.print(Math.max(a,Math.max(b,c)) * 100);
}
}
}
다른 분들의 깔끔하고 간결한 코드를 보고 많이 배웠다
Math.max 함수를 새로 배웠다!
'내가 보려고 만든 공부정리 > 백준' 카테고리의 다른 글
[백준/자바] 11022 A+B -8 (0) | 2022.07.08 |
---|---|
[백준/자바] 8393 합 (0) | 2022.07.05 |
[백준/자바] 10950 A+B (0) | 2022.07.05 |
[백준/자바] 2739 구구단 (0) | 2022.07.05 |
[백준/자바] 10171번: 고양이 (0) | 2022.06.30 |