<문제>

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

 

 

<풀이>

import sys
input = sys.stdin.readline
N = int(input())

arr = list(map(int, input().split()))
sorted_arr = sorted(set(arr))
compression_dict = {x: i for i, x in enumerate(sorted_arr)}

for i in arr:
    print(compression_dict[i], end=' ')

 

- 중복을 제거하기 위해 set

- set에서 sorted -> 배열

- 배열을 enumerate로 dictionary

- 기존 순서는 처음 배열 이용해서 순회

'TIL > [파이썬] 1일 1코테' 카테고리의 다른 글

개미_백준3048  (0) 2025.02.20
세준세비_백준1524  (0) 2025.02.19
[정렬] H-Index_프로그래머스  (0) 2025.02.17
파일 정리_백준20291  (0) 2025.02.17
회전초밥_백준28107  (0) 2025.02.15

+ Recent posts