짱이 될거야
백준 20920: 영단어 암기는 괴로워 Python 본문
https://www.acmicpc.net/problem/20920
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])
'알고리즘' 카테고리의 다른 글
백준 1158: 요세푸스 문제 Python (0) | 2022.12.01 |
---|---|
백준 5014: 스타트링크 Python (BFS) (0) | 2022.11.29 |
백준 7569: 토마토 Python (BFS) (0) | 2022.11.28 |
백준 3009: 네 번째 점 Python (0) | 2022.11.25 |
백준 25501: 재귀의 귀재 Python (0) | 2022.11.25 |
Comments