본문 바로가기
python-algorithm

백준 2303 숫자 게임

by 무적김두칠 2022. 10. 27.

https://www.acmicpc.net/problem/2303

 

2303번: 숫자 게임

N명이 모여 숫자 게임을 하고자 한다. 각 사람에게는 1부터 10사이의 수가 적혀진 다섯 장의 카드가 주어진다. 그 중 세 장의 카드를 골라 합을 구한 후 일의 자리 수가 가장 큰 사람이 게임을 이

www.acmicpc.net

 

1
2
3
4
5
6
7
8
9
10
11
12
13
from itertools import combinations
 
n=int(input())
answer=[]
for i in range(n):
    nums = list(map(int, input().split()))
    mymax=0
    for nums_com in (list(combinations(nums, 3))):
        if mymax<sum(nums_com)%10:
            mymax = sum(nums_com)%10
    answer.append([i+1,mymax])
answer.sort(key=lambda x:(-x[1],-x[0]))
print(answer[0][0])
cs

itertools의 combinations를 써서 숫자들 조합을 만들고 정렬 하면 됩니다

Using combinations from itertools, Make a numbers' combinations and Sort

반응형

'python-algorithm' 카테고리의 다른 글

백준 3985 롤 케이크  (0) 2022.10.28
백준 4659 비밀번호 발음하기  (0) 2022.10.27
백준 10174 팰린드롬  (0) 2022.10.27
백준 2635 수 이어가기  (0) 2022.10.27
백준 16395 파스칼의 삼각형  (0) 2022.10.27

댓글