[백준/코틀린] 10816번: 숫자 카드 2
실버 4
링크
풀이
숫자 카드에 적힌 정수의 개수를 세기 위해 HashMap을 사용합니다.
코드
1
2
3
4
5
6
7
8
9
10
11
12
13
fun main() {
val n = readln().toInt()
val nums = readln().split(" ").map { it.toInt() }
val hashMap = hashMapOf<Int, Int>()
val m = readln().toInt()
nums.forEach { hashMap[it] = hashMap.getOrDefault(it, 0) + 1 }
readln().split(" ").map { it.toInt() }
.joinToString(" ") { "${hashMap.getOrDefault(it, 0)}" }
.also { println(it) }
}
This post is licensed under CC BY 4.0 by the author.