백준 20920번: 영단어 암기는 괴로워 #Python

ColorlessDia·2024년 8월 16일

algorithm/baekjoon

목록 보기
271/836
import sys

N, M = map(int, sys.stdin.readline().split())

word_dict = dict()

for _ in range(N):
    word = sys.stdin.readline().rstrip()

    if len(word) < M:
        continue
    
    if word in word_dict:
        word_dict[word] += 1
    else:
        word_dict[word] = 1

sorted_word_dict = sorted(word_dict.items(), key=lambda x: (-x[1], -len(x[0]), x[0]))

for word, count in sorted_word_dict:
    print(word)

0개의 댓글