[BOJ] 1302


質問する
me
import sys
input = sys.stdin.readline

N=int(input())
books=[input().strip() for _ in range(N)]
set_books=set(books)
book_cnts=[0]*N
max_cnt,max_book_name=0,''
for book in set_books:
    cnt=books.count(book)
    if max_cnt < cnt:
        max_cnt=cnt
        max_book_name=book
    elif max_cnt==cnt and book<max_book_name:
        max_book_name=book
print(max_book_name)
solution
n=int(input())
books={}
for _ in range(n):
	book=input()
    if book not in books:
    	books[book]=1
    else:
    	books[book]+=1
target=max(books.value())
array=[]
for book,number in books.items():
	if number==target:
    	array.append(book)
print(sorted(array)[0])
  • ディックシャナリ計
  • ディクショナリソート同じ内容を配列に配置してソートし、0番目の
  • を抽出する.