문제 링크: https://www.acmicpc.net/problem/2309
2309번: 일곱 난쟁이
아홉 개의 줄에 걸쳐 난쟁이들의 키가 주어진다. 주어지는 키는 100을 넘지 않는 자연수이며, 아홉 난쟁이의 키는 모두 다르며, 가능한 정답이 여러 가지인 경우에는 아무거나 출력한다.
www.acmicpc.net
9명의 난쟁이의 키를 입력 받으면서 총 합을 같이 구함.
sort한후, 각 pair의 키들을 총 합에서 뺀값이 100일때를 찾고, 그때 나머지 7명의 키를 출력하면 됨.
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
|
#include <bits/stdc++.h>
using namespace std;
int height[10];
int main() {
ios_base::sync_with_stdio(0);
cin.tie(0);
int sum = 0;
for(int i = 0; i < 9; i++) {
cin >> height[i];
sum += height[i];
}
sort(height, height + 9);
for(int i = 0; i < 9; i++) {
for(int j = i + 1; j < 9; j++) {
if(sum - height[i] - height[j] == 100) {
for(int k = 0; k < 9; k++) {
if(k == i || k == j) continue;
cout << height[k] << '\n';
}
return 0;
}
}
}
return 0;
}
http://colorscripter.com/info#e" target="_blank" style="color:#4f4f4ftext-decoration:none">Colored by Color Scripter
|
'KOI > 초등부' 카테고리의 다른 글
백준 2667 단지번호붙이기 (KOI 1996 초등부 1번) (0) | 2020.03.07 |
---|