영단어 암기는 괴로워

 

20920번: 영단어 암기는 괴로워

첫째 줄에는 영어 지문에 나오는 단어의 개수 $N$과 외울 단어의 길이 기준이 되는 $M$이 공백으로 구분되어 주어진다. ($1 \leq N \leq 100\,000$, $1 \leq M \leq 10$) 둘째 줄부터 $N+1$번째 줄까지 외울 단

www.acmicpc.net

 

내 코드

from sys import stdin

N, M = map(int, stdin.readline().split())
# print(N, M)
dicList = []
dic = {}


for _ in range(N):
    word = stdin.readline().strip()
    if len(word) >= M:
        dicList.append(word)
# print(dicList)

for word in dicList:
    if not word in dic:
        dic[word] = 1
    else:
        dic[word] += 1

keys = dic.keys()
# print(dic)
dic = sorted(dic.items(), key=lambda x: (-x[1], -len(x[0]), x[0]))
for word, count in dic:
    print(word)
728x90

+ Recent posts