[백준] 2480번 - 주사위 세개 [Java][C++]
[백준] 2480번 - 주사위 세개 [Java][C++]
1. 문제 풀이
주사위의 세 눈이 모두 같은 경우 한 가지, 주사위의 두 눈이 서로 같은 경우 세 가지, 나머지 케이스로 분류하는 조건문을 활용하면 해결할 수 있다.
2. 코드
1. 구현 [Java]
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
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 && b == c) {
System.out.println(10000 + a * 1000);
} else if (a == b) {
System.out.println(1000 + a * 100);
} else if (b == c) {
System.out.println(1000 + b * 100);
} else if (c == a) {
System.out.println(1000 + c * 100);
} else {
System.out.println(Math.max(a, Math.max(b, c)) * 100);
}
}
}
2. 구현 [C++]
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
#include <bits/stdc++.h>
using namespace std;
int main() {
ios::sync_with_stdio(false);
cin.tie(nullptr);
int a, b, c;
cin >> a >> b >> c;
if (a == b && b == c) {
cout << 10000 + a * 1000;
} else if (a == b) {
cout << 1000 + a * 100;
} else if (b == c) {
cout << 1000 + b * 100;
} else if (c == a) {
cout << 1000 + c * 100;
} else {
cout << max({a, b, c}) * 100;
}
}
3. 풀이 정보
1. 구현 [Java]
| 언어 | 시간 | 메모리 | 코드 길이 |
|---|---|---|---|
| Java 11 | 100 ms | 14064 KB | 837 B |
2. 구현 [C++]
| 언어 | 시간 | 메모리 | 코드 길이 |
|---|---|---|---|
| C++ 17 | 0 ms | 2020 KB | 450 B |
This post is licensed under CC BY 4.0 by the author.