[백준/코틀린] 2108번: 통계학
실버 2
링크
풀이
생략
코드
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
import kotlin.math.roundToInt
fun main() {
val n = readln().toInt()
val nums = List(n) { readln().toInt() }.sorted()
val frequency = nums.groupingBy { it }.eachCount()
val maxCnt = frequency.maxOf { it.value }
val mode = frequency.filter { it.value == maxCnt }.keys.sorted()
println((nums.sum().toDouble() / n).roundToInt())
println(nums[n / 2])
println(
if (mode.size == 1) mode[0]
else mode[1]
)
println(nums.last() - nums.first())
}
This post is licensed under CC BY 4.0 by the author.