[백준/코틀린] 1181번: 단어 정렬
실버 5
링크
풀이
sortedWith를 사용하여 정렬 기준을 지정합니다.
- 오름차순 정렬 ->
compareBy - 내림차순 정렬 ->
compareByDescending
코드
1
2
3
4
5
6
7
8
9
10
fun main() = with(StringBuilder()) {
val words = List(readln().toInt()) { readln() }
words.distinct()
.sortedWith(compareBy(String::length, { it }))
.forEach { appendLine(it) }
println(toString())
}
This post is licensed under CC BY 4.0 by the author.