문제
알고리즘
- collections 모듈에 Counter 클래스를 사용한다.
- 람다 정렬을 통해 개수를 내림차순으로, 이름을 오름차순으로 정렬한다.
코드
import sys
from collections import Counter
n = int(sys.stdin.readline())
temp = []
for _ in range(n):
temp.append(str(sys.stdin.readline().strip()))
res = Counter(temp)
# 람다 정렬을 통해 개수를 내림차순으로 이름을 오름차순으로 정렬
res = sorted(res.items(), key=(lambda x: (-x[1], x[0])))
# 출력
print(res[0][0])
github
'CodingTest > Baekjoon' 카테고리의 다른 글
[baekjoon] 백준 7662번(파이썬): 이중 우선순위 큐 (0) | 2021.10.14 |
---|---|
[baekjoon] 백준 3986번(파이썬): 좋은 단어 (0) | 2021.10.13 |
[baekjoon] 백준 2161번(파이썬): 카드1 (0) | 2021.10.11 |
[baekjoon] 백준 7785번(파이썬): 회사에 있는 사람 (0) | 2021.10.11 |
[baekjoon] 백준 4195번(파이썬): 친구 네트워크 (0) | 2021.10.10 |