• Home
  • About
    • Moon photo

      Moon

      개발자는 자고 싶다.

    • Learn More
    • Twitter
    • Facebook
    • Instagram
    • Github
    • Steam
  • Posts
    • All Posts
    • All Tags
  • Projects

백준 - 11866 오세푸스 문제 0

06 Jun 2022

Reading time ~1 minute

문제

11866 오세푸스 문제 0

screencapture

답

kotlin code

fun main() {
    q11866()
}

fun q11866() {
    val input = readln().split(" ").map { it.toInt() }
    val size = input.first()
    val step = input.last()
    val inputs = java.util.LinkedList<Int>()
    inputs.add(size)
    for(i in 1 until size) {
        inputs.add(i)
    }
    val outputs = IntArray(size) { -1 }

    var curI = 1
    var outputIndex = 0
    while (inputs.isNotEmpty()) {
        curI = (curI + step - 1) % inputs.size
        outputs[outputIndex++] = inputs[curI]
        inputs.removeAt(curI)
    }

    println(outputs.contentToString().replace("[", "<").replace("]", ">"))
}


baekjoonkotlin코틀린백준실버구현자료 구조큐 Share Tweet +1