Notice
Recent Posts
Recent Comments
Link
«   2024/05   »
1 2 3 4
5 6 7 8 9 10 11
12 13 14 15 16 17 18
19 20 21 22 23 24 25
26 27 28 29 30 31
Tags
more
Archives
Today
Total
관리 메뉴

짱이 될거야

백준 20920: 영단어 암기는 괴로워 Python 본문

알고리즘

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

jeong57 2022. 11. 29. 10:51

https://www.acmicpc.net/problem/20920

 

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

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

www.acmicpc.net

 

import sys
input = sys.stdin.readline

N, M = map(int, input().split())    # N: 단어 개수, M: 길이 기준
words = {}     # result = {'apple': [5, 1, 'apple'],}
for i in range(N):
    word = input().strip()
    if len(word) < M:
        continue
    else:
        if words.get(word):
            words[word][1] += 1
        else:
            words[word] = [len(word), 1, word]

result = sorted(words.items(), key=lambda x: (-x[1][1], -x[1][0], x[1][2]))
for r in result:
    print(r[0])
Comments