시배's Android
Algorithm | 백준 Kotlin 1158 요세푸스 문제 본문
private fun main(){
val (n,k) = readLine()!!.split(" ").map { it.toInt() }
val people = mutableListOf<Int>().also { it.addAll(1..n) }
val result = mutableListOf<Int>()
var i = 0
while(people.size > 1){
i = (i + k-1) % people.size
result.add(people.removeAt(i))
}
result.add(people[0])
print("<${result.joinToString(", ")}>")
}
'Algorithm' 카테고리의 다른 글
Algorithm | 백준 Kotlin 6443 애너그램 (0) | 2023.09.23 |
---|---|
Algorithm | 백준 Kotlin 2553 마지막 팩토리얼 수 (0) | 2023.09.23 |
Algorithm | 백준 Kotlin 1965 상자넣기 (0) | 2023.09.16 |
Algorithm | 백준 Kotlin 15664 N과 M (10) (0) | 2023.09.16 |
Algorithm | 백준 Kotlin 2776 암기왕 (0) | 2023.09.16 |