[백준] 18870 - 좌표 압축 / Python / 실버 2

KimYoungWoong·2022년 8월 23일
0

BOJ

목록 보기
12/31
post-thumbnail

🚩문제 주소


📄풀이


입력 받은 좌표들을 set을 활용해 중복을 제거한 후, 정렬을 해줍니다.
정렬한 배열의 원소들을 딕셔너리에 인덱스와 함께 저장합니다.
처음 입력 받았던 좌표 순서대로 딕셔너리에서 검색해서 출력합니다.



👨‍💻코드


n = int(input())
x = list(map(int, input().split()))
x_sort = sorted(set(x))

dic = {}
for i in range(len(x_sort)):
  dic[x_sort[i]] = i

for i in x:
  print(dic[i], end=' ')

profile
블로그 이전했습니다!! https://highero.tistory.com

0개의 댓글