import Foundation
let N = Int(readLine()!)!
var tuples = [(x: Int, y: Int)]()
for _ in 1...N {
let xy = readLine()!.components(separatedBy: " ").map { Int($0)! }
let x = xy[0]
let y = xy[1]
tuples.append((x, y))
}
var ranks = [Int]()
for tuple in tuples {
let rank = tuples.filter { $0.x > tuple.x && $0.y > tuple.y }.count + 1
ranks.append(rank)
}
for rank in ranks {
if rank.hashValue == ranks.last?.hashValue {
print(rank)
} else {
print(rank, terminator: " ")
}
}
tuple에 데이터를 저장한뒤 비교해서 풀었다.
반응형
'📝 코테 > BOJ' 카테고리의 다른 글
[Swift] 백준10845 큐 (0) | 2023.03.28 |
---|---|
[Swift] 백준9012 괄호 (0) | 2023.03.28 |
[Swift] 백준10773 (0) | 2023.03.27 |
[Swift] 백준2775 (0) | 2023.03.27 |
[Swift] 백준2609 (0) | 2023.03.27 |