Post

[BOJ] 18870. ์ขŒํ‘œ์••์ถ•(python)

๐Ÿ“Œ๋ฌธ์ œ

Alt text

๐Ÿ’ช์•„์ด๋””์–ด

  1. ์ค‘๋ณต๋˜๋Š” ์ˆ˜ ์—†์• ๊ธฐ -> set
  2. set ์ •๋ ฌ
    ์˜ค๋ฆ„์ฐจ์ˆœ์œผ๋กœ ์ •๋ ฌ๋˜๊ธฐ๋•Œ๋ฌธ์— ์ธ๋ฑ์Šค๊ฐ’์ด ๋‚˜๋ณด๋‹ค ์ž‘์€ ๊ฐ’๋“ค์˜ ์ˆ˜
  3. ์ •๋ ฌํ•œ set์˜ ์ธ๋ฑ์Šค ์ถœ๋ ฅ

    ๐Ÿฅ‚์ฝ”๋“œ

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
import sys
input = sys.stdin.readline

n = int(input())
input_nums = list(map(int,input().split()))
num = set(input_nums)

if n==1: 
    print(0)
    exit(0)

answer_dict=dict()
for i, k in enumerate(sorted(list(num))):
    answer_dict[k]=i

for number in input_nums:
    print(answer_dict[number],end= ' ')
This post is licensed under CC BY 4.0 by the author.

Comments powered by Disqus.