📝 코테/BOJ
[Swift] 백준7568 덩치
JerryiOS
2023. 3. 28. 14:06
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에 데이터를 저장한뒤 비교해서 풀었다.
반응형