영단어 암기는 괴로워
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
'Algorithm&CodingTest > Baekjoon' 카테고리의 다른 글
[Baekjoon] [20310] 실버3 - 타노스 Python (0) | 2024.05.05 |
---|---|
[Baekjoon] [21921] 실버3 - 블로그 Python (1) | 2024.01.31 |
[Baekjoon] [13305] 실버3 - 주유소 Python (1) | 2024.01.29 |
[Baekjoon] [2164] 실버4 - 카드2 Python (0) | 2024.01.29 |
[Baekjoon] [17266] 실버4 - 어두운 굴다리 Python (1) | 2024.01.29 |