코딩테스트/Python
[Python] 백준 #2910 - 빈도 정렬
yo~og
2022. 5. 16. 02:16
문제
https://www.acmicpc.net/problem/2910
2910번: 빈도 정렬
첫째 줄에 메시지의 길이 N과 C가 주어진다. (1 ≤ N ≤ 1,000, 1 ≤ C ≤ 1,000,000,000) 둘째 줄에 메시지 수열이 주어진다.
www.acmicpc.net
풀이
from collections import Counter
n,m = map(int,input().split())
arr = list(map(int,input().split()))
x = Counter(arr).most_common()
for a,b in x:
for _ in range(b):
print(a,end=' ')
Counter(arr).most_common()를 사용해준다.
꺄 숏코딩 또 올라갔다!