지나가던 개발자
[Python] 백준 24175번(Tokyo2020) 문제 풀이 본문
from collections import Counter
while True:
players = []
for i in range(int(input())):
d = input().split()
players.append([int(d[0]), d[2]])
if players == []:
break
players.sort(key=lambda x:x[0])
print(Counter([x[0] for x in players if x[1] == 'Gold']).most_common(1)[0][0], Counter([x[0] for x in players]).most_common(1)[0][0])
파이썬에서 리스트의 최빈값을 구하기 위해서는 from collections import Counter를 해준 후 Counter(리스트).most_common(1)[0][0] 을 하면 된다.
'PS > Python' 카테고리의 다른 글
[Python] 백준 13773번(Olympic Games) 문제 풀이 (0) | 2022.10.26 |
---|---|
[Python] 백준 20977번(JOI ソート (JOI Sort)) 문제 풀이 (0) | 2022.10.25 |
[Python] 백준 13985번(Equality) 문제 풀이 (0) | 2022.10.24 |
[Python] 백준 15965번(K번째 소수) 문제 풀이 (0) | 2022.10.23 |
[Python] 백준 4355번(서로소) 문제 풀이 (1) | 2022.10.22 |
Comments