문제
https://www.acmicpc.net/problem/2309
2309번: 일곱 난쟁이
아홉 개의 줄에 걸쳐 난쟁이들의 키가 주어진다. 주어지는 키는 100을 넘지 않는 자연수이며, 아홉 난쟁이의 키는 모두 다르며, 가능한 정답이 여러 가지인 경우에는 아무거나 출력한다.
www.acmicpc.net
문제풀이
|
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
26
27
28
29
30
31
32
33
|
public class BOJ_2309_일곱난쟁이 {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int [] smalls = new int[9];
int sum =0;
for (int i = 0; i < 9; i++) {
smalls[i]=sc.nextInt();
sum += smalls[i];
}
Arrays.sort(smalls);
int spyA=0 ,spyB=0;
for (int i = 0; i < 9; i++) {
for (int j = i+1; j < 9; j++) {
if(sum-smalls[i]-smalls[j]==100) {
spyA=i;
spyB=j
}
}
}
for (int i = 0; i < 9; i++) {
if(i!=spyA && i!=spyB) {
System.out.println(smalls[i]);
}
}
}
}
|
cs |
'Algorithm > BOJ' 카테고리의 다른 글
| [백준 알고리즘] 백준 2231번 - 분해합(JAVA) (0) | 2022.01.16 |
|---|---|
| [백준 알고리즘] 백준 16916번 - 부분 문자열(JAVA) (0) | 2022.01.14 |
| [백준 알고리즘] 백준 8911번 - 거북이 (JAVA) (0) | 2022.01.14 |