Post

[백준/코틀린] 11650번: 좌표 정렬하기

실버 5

링크

11650번: 좌표 정렬하기

풀이

sortedWith를 사용하여 정렬 기준을 지정합니다.

  • 오름차순 정렬 -> compareBy
  • 내림차순 정렬 -> compareByDescending

코드

1
2
3
4
5
6
7
8
9
10
11
12
13
14
data class Point(
    val x: Int,
    val y: Int,
)

fun main() = with(StringBuilder()) {
    List(readln().toInt()) { readln().split(" ").map { it.toInt() } }
        .map { Point(it[0], it[1]) }
        .sortedWith(compareBy(Point::x, Point::y))
        .forEach { appendLine("${it.x} ${it.y}") }

    println(toString())
}

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