https://www.acmicpc.net/problem/1302
python의 dictionary 활용
- dictionary에 해당 책이 없을경우 key=책 이름, value=1 추가
- dictionary에 해당 책이 있을경우 value 값에 +1
N = int(input())
total = {}
for i in range(N):
temp = input()
if total.get(temp):
total[temp] += 1
else:
total[temp] = 1
ans = ''
cnt = 0
for item in total.items():
if item[1] > cnt:
ans = item[0]
cnt = item[1]
elif item[1] == cnt and ans > item[0]:
ans = item[0]
print(ans)
'알고리즘 문제 풀이 > Python' 카테고리의 다른 글
python 백준 5639 이진 검색 트리 (0) | 2022.06.20 |
---|---|
python 백준 1916 최소비용 구하기 (0) | 2022.06.19 |
python 백준 10815 숫자카드 (0) | 2022.06.15 |
python 1543 문서 검색 (0) | 2022.06.14 |
python 백준 17952 과제는 끝나지 않아! (0) | 2022.06.13 |