From 70f8b0eeff4acced6a0ad2b339f5a73c22515c75 Mon Sep 17 00:00:00 2001 From: songyc macbook Date: Mon, 22 Sep 2025 20:06:43 +0900 Subject: [PATCH] 20250922 baekjoon --- code_study/Baekjoon/swift/1015.swift | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) create mode 100644 code_study/Baekjoon/swift/1015.swift diff --git a/code_study/Baekjoon/swift/1015.swift b/code_study/Baekjoon/swift/1015.swift new file mode 100644 index 0000000..1b4e87c --- /dev/null +++ b/code_study/Baekjoon/swift/1015.swift @@ -0,0 +1,25 @@ +if let N = Int(readLine() ?? "0"), + let input = readLine(), + let A: [Int] = input.split(separator: " ").compactMap({Int($0)}) as? [Int], + A.count == N +{ + let mapA = A.enumerated().map({ (i, v) in + return (value: v, index: i) + }) + + let sortedA = mapA.sorted(by: { + if $0.value == $1.value { + return $0.index < $1.index + } + return $0.value < $1.value + }) + + var P: [Int] = Array(repeating: 0, count: N) + for (sortedIndex, element) in sortedA.enumerated() { + P[element.index] = sortedIndex + } + + for p in P { + print(p, terminator: " ") + } +}