https://www.acmicpc.net/problem/10814
import Foundation
struct Person {
var name: String
var age: Int
var index: Int
init(_ info: [String], index: Int) {
self.name = info[1]
self.age = Int(info[0])!
self.index = index
}
}
let N = Int(readLine()!)!
var people: [Person] = []
for index in 0..<N {
let info = readLine()!.components(separatedBy: " ")
let person = Person(info, index: index)
people.append(person)
}
people.sort {
if $0.age == $1.age {
return $0.index < $1.index
}
return $0.age < $1.age
}
people.forEach {
print("\($0.age) \($0.name)")
}'알고리즘' 카테고리의 다른 글
| [Swift] 국영수 (0) | 2025.08.20 |
|---|---|
| [Swift] Queue와 Stack 구현하기 (1) | 2023.12.24 |
| [Swift] 달리기 경주 (0) | 2023.10.24 |