백준 & 프로그래머스
백준.일곱 난쟁이.2309.py
concho
2023. 9. 19. 12:41
https://www.acmicpc.net/problem/2309
2309번: 일곱 난쟁이
아홉 개의 줄에 걸쳐 난쟁이들의 키가 주어진다. 주어지는 키는 100을 넘지 않는 자연수이며, 아홉 난쟁이의 키는 모두 다르며, 가능한 정답이 여러 가지인 경우에는 아무거나 출력한다.
www.acmicpc.net
import sys
# 난쟁이 9명에서 2명을 빼는 경우 => 9C2 => 36
# 조합 구현 귀찮아서 순열로
def solution():
person_9, person_7_gr, combination_set = [], [], set()
for _ in range(9):
person_9.append(int(sys.stdin.readline().rstrip()))
for i in range(9):
for j in range(9):
if i != j:
tm_person = person_9.copy()
del tm_person[i]
del tm_person[j if i > j else j-1]
person_7_gr.append(tm_person)
for person_7 in person_7_gr:
if sum(person_7) == 100:
person_7.sort()
for person in person_7:
print(person)
break
if __name__ == '__main__':
solution()