Notice
Recent Posts
Recent Comments
일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
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
- Kaggle
- hackerrank
- 더현대서울 맛집
- programmers
- gs25
- 캐치카페
- PYTHON
- 편스토랑
- Docker
- 맥북
- 코로나19
- Real or Not? NLP with Disaster Tweets
- github
- ChatGPT
- 백준
- 프로그래머스
- 우분투
- SW Expert Academy
- Baekjoon
- 프로그래머스 파이썬
- ubuntu
- 파이썬
- 금융문자분석경진대회
- 데이콘
- AI 경진대회
- Git
- 자연어처리
- leetcode
- 편스토랑 우승상품
- dacon
Archives
- Today
- Total
솜씨좋은장씨
[BaekJoon] 2910번 : 빈도 정렬 (Python) 본문
728x90
반응형

코딩 1일 1문제! 오늘은 555일차 문제! 백준의 빈도 정렬 입니다.
2910번: 빈도 정렬
첫째 줄에 메시지의 길이 N과 C가 주어진다. (1 ≤ N ≤ 1,000, 1 ≤ C ≤ 1,000,000,000) 둘째 줄에 메시지 수열이 주어진다.
www.acmicpc.net
👨🏻💻 코드 ( Solution )
import sys
def frequency_sorting(numbers):
order_cnt_dict = {}
priority_dict = {}
for idx, number in enumerate(numbers):
if number not in order_cnt_dict.keys():
order_cnt_dict[number] = [0, idx]
order_cnt_dict[number][0] += 1
order_cnt_items = order_cnt_dict.items()
sorted_numbers = [num[0] for num in sorted(order_cnt_items, key=lambda x: (-x[1][0], x[1][1]))]
for idx, num in enumerate(sorted_numbers):
priority_dict[num] = idx
numbers = sorted(numbers, key=(lambda x: priority_dict[x]))
return " ".join(map(str, numbers))
if __name__ == "__main__":
N, C = map(int, input().split())
numbers = list(map(int, input().split()))
print(frequency_sorting(numbers))
GitHub - SOMJANG/CODINGTEST_PRACTICE: 1일 1문제 since 2020.02.07
1일 1문제 since 2020.02.07. Contribute to SOMJANG/CODINGTEST_PRACTICE development by creating an account on GitHub.
github.com
'Programming > 코딩 1일 1문제' 카테고리의 다른 글
[BaekJoon] 1735번 : 분수 합 (Python) (0) | 2021.12.06 |
---|---|
[BaekJoon] 2752번 : 세수정렬 (Python) (0) | 2021.12.05 |
[BaekJoon] 11659번 : 구간 합 구하기 4 (Python) (0) | 2021.12.03 |
[BaekJoon] 10952번 : A+B - 5 (Python) (0) | 2021.12.02 |
[SW Expert Academy] 2029번 : 몫과 나머지 출력하기 (Python) (0) | 2021.12.01 |