[BOJ]3009:7ジュニア



🔒 例

>> 20
>> 7
>> 23
>> 19
>> 10
>> 15
>> 25
>> 8
>> 13

7
8
10
13
19
20
23

🔧 に答える

1. h = [int(sys.stdin.readline().rstrip()) for _ in range(9)]
2. combinations 활용
3. 정답의 경우의 수가 많지만 하나만 출력하도록 설정 !

🔑 答案用紙

import sys
from itertools import combinations
h = [int(sys.stdin.readline().rstrip()) for _ in range(9)]

hs = list(combinations(h, 7))
for i in range(len(hs)):
    if sum(hs[i]) == 100:
        hs[i] = sorted(hs[i])
        for j in hs[i]:
            print(j)
        break

💡 コンセプト

### sorted : return sorted list/dict/...
d = [1, 5, 4, 3, 8, 0]
s = sorted(d)			# [0, 1, 3, 4, 5, 8]
s = sorted(d, reverse=True)	# [8, 5, 4, 3, 1, 0]

dict = {'a': 21, 'c': 10, 'b': 19 }
# key 기준, 전체 정렬 :: [('a', 21), ('b', 19), ('c', 10)]
s = sorted(dict.items())	
# value 기준, 전체 정렬 :: [('c', 10), ('b', 19), ('a', 21)]
s = sorted(dict.items(), key=operator.itemgetter(1))
s = sorted(dict.items(), key=lambda x: x[1])	

# key만 정렬 :: ['a', 'b', 'c']
s = sorted(dict.keys())
s = sorted(dict)
# value만 정렬 :: [10, 19, 21]
s = sorted(dict.values())

# 우선순위로 정렬 :: [('c', 10), ('b', 19), ('a', 21)]
s = sorted(dict.items(), key=lambda x: (x[1], x[0])) 

### sort: sort its list
l = [4, 2, 3, 5, 1]
print(l.sort())	# [4, 2, 3, 5, 1]