728x90
반응형
풀이과정
자료구조와 배열의 아주 기본적인 문제. 딕셔너리에 책의 종류와 개수를 카운트해주고, 가장 많은 개수를 가진 책들만 리스트로 뽑은 뒤 사전순으로 정렬하여 [0]번째를 출력한다.
import sys; input = sys.stdin.readline
N = int(input())
dic = {}
for _ in range(N):
book = input().rstrip()
if book in dic:
dic[book] += 1
else:
dic[book] = 1
top = max(dic.values())
result = []
for key, value in dic.items():
if top == value:
result.append(key)
print(sorted(result)[0])
728x90
반응형
'Algorithm > Baekjoon' 카테고리의 다른 글
[Baekjoon] 3003 Python (0) | 2023.08.30 |
---|---|
[Baekjoon] 1068 Python (0) | 2023.08.29 |
[Baekjoon] 1149 Python (0) | 2023.08.29 |
[Baekjoon] 2606 Python (0) | 2023.08.28 |
[Baekjoon] 9375 Python (0) | 2023.08.28 |