KotlinAlgorithm#5 (BOJ2164)

박채빈·2021년 10월 22일
0

KotlinAlgorithm

목록 보기
5/28
post-thumbnail

BOJ2164 카드2

링크

코드

import java.io.*
import java.util.*

fun solution1() {
    val N = readLine()!!.toInt()
    val queue: LinkedList<Int> = LinkedList()

    queue.addAll(1..N)

    while(queue.size > 2) {
        queue.pop()
        queue.offer(queue.pop())
    }

    println(queue.last)
}

fun solution2() {
    val br = BufferedReader(InputStreamReader(System.`in`))
    val bw = BufferedWriter(OutputStreamWriter(System.out))

    val N = br.readLine().toInt()
    val queue: LinkedList<Int> = LinkedList()

    queue.addAll(1..N)

    while(queue.size > 2) {
        queue.poll()
        queue.offer(queue.poll())
    }

    bw.write("${queue.last}\n")

    bw.flush()
    br.close()
    bw.close()
}

fun main() {
    solution1()
    solution2()
}
profile
안드로이드 개발자

0개의 댓글