백준 1015번 수열 정렬

Solution

import sys

si = sys.stdin.readline

n = int(input())
a = list(map(int, input().split()))


class Element:
    def __init__(self, value, index):
        self.value = value
        self.index = index


b = []
for i in range(n):
    b.append(Element(a[i], i))

b.sort(key=lambda x: x.value)

p = [0] * n
for i in range(n):
    p[b[i].index] = i
for i in range(n):
    print(p[i], end=' ')
  • 모범 풀이
import sys

n = int(sys.stdin.readline())
a = list(map(int, sys.stdin.readline().split()))
B = [(x, i) for i, x in enumerate(a)]
B.sort()
P = [0 for _ in range(n)]
for i in range(n):
    P[B[i][1]] = i
for i in range(n):
    print(P[i], ' ')