[백준] 창영마을 (3028)(kotlin)
문제 설명
입력 및 출력
» 입력
첫째 줄에 정인이가 컵을 섞은 순서가 주어진다. 이 순서는 A, B, C중 하나이고, 문제에 있는 그림을 참고하면 된다. 정인이는 컵을 최대 50번 섞는다.
» 출력
공이 가장 왼쪽 컵에 있으면 1, 중앙에 있는 컵에 있으면 2, 오른쪽에 있는 컵에 있으면 3을 출력한다.
예제 입출력(테스트케이스)
| 입력 | 출력 | 
|---|---|
| AB | 3 | 
문제 풀이1
import java.io.BufferedReader
import java.io.InputStreamReader
fun main(args: Array<String>) = with(BufferedReader(InputStreamReader(System.`in`))) {
    val shff = readLine()
    var game = booleanArrayOf(true, false, false)
    shff.forEach {
        game.shuffleBall(it)
    }
    game.forEachIndexed { index, b ->
        if (b) println(index + 1)
    }
}
fun BooleanArray.shuffleBall(ch: Char) {
    when (ch) {
        'A' -> {
            val tmp = this[0]
            this[0] = this[1]
            this[1] = tmp
        }
        'B' -> {
            val tmp = this[1]
            this[1] = this[2]
            this[2] = tmp
        }
        else -> {
            val tmp = this[0]
            this[0] = this[2]
            this[2] = tmp
        }
    }
}