BAEKJOON #18870 좌표 압축

2021. 4. 26. 11:11개발노트

이 문제의 저작권은 BAEKJOON에 있습니다.

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

 

풀이

  1. 주어진 숫자 리스트의 중복을 set을 이용해 제거, sorted로 정렬한다.
  2. for문으로 정렬된 리스트를 돌며 숫자를 key, 순위를 value로 딕셔너리에 추가
  3. 처음 주어진 숫자 리스트 순서대로 순위를 출력
# 좌표 압축
# https://www.acmicpc.net/problem/18870

N = int(input())
num_list = list(map(int, input().split(" ")))

num_dict = {}
for i, n in enumerate(sorted(set(num_list))):
    num_dict[n] = i
for n in num_list:
    print(f"{num_dict[n]}", end=" ")
print()