Post

[백준/코틀린] 10814번: 나이순 정렬

실버 5

링크

10814번: 나이순 정렬

풀이

SortedBy함수의 안정 정렬(stable sort)특성을 이용하여 정렬합니다.

코드

1
2
3
4
5
6
7
8
9
fun main() {
    val n = readln().toInt()
    val members = List(n) { readln().split(" ") }
        .map { it[0].toInt() to it[1] }

    members.sortedBy { it.first }
        .forEach { println("${it.first} ${it.second}") }
}

This post is licensed under CC BY 4.0 by the author.