20250922 baekjoon
This commit is contained in:
parent
269f9dca72
commit
70f8b0eeff
25
code_study/Baekjoon/swift/1015.swift
Normal file
25
code_study/Baekjoon/swift/1015.swift
Normal file
@ -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: " ")
|
||||||
|
}
|
||||||
|
}
|
||||||
Loading…
x
Reference in New Issue
Block a user