結果

問題 No.24 数当てゲーム
ユーザー yo-kondoyo-kondo
提出日時 2018-03-23 23:15:18
言語 Kotlin
(1.9.23)
結果
AC  
実行時間 324 ms / 5,000 ms
コード長 1,607 bytes
コンパイル時間 13,943 ms
コンパイル使用メモリ 442,820 KB
実行使用メモリ 56,956 KB
最終ジャッジ日時 2024-04-30 17:21:42
合計ジャッジ時間 16,446 ms
ジャッジサーバーID
(参考情報)
judge2 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 311 ms
56,932 KB
testcase_01 AC 312 ms
56,884 KB
testcase_02 AC 313 ms
56,816 KB
testcase_03 AC 313 ms
56,892 KB
testcase_04 AC 324 ms
56,824 KB
testcase_05 AC 313 ms
56,956 KB
testcase_06 AC 313 ms
56,792 KB
testcase_07 AC 312 ms
56,820 KB
testcase_08 AC 312 ms
56,868 KB
testcase_09 AC 309 ms
56,796 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
Main.kt:7:10: warning: parameter 'args' is never used
fun main(args: Array<String>) {
         ^

ソースコード

diff #

package yukicoder.no24

/**
 * エントリポイント
 * @param args コマンドライン引数
 */
fun main(args: Array<String>) {
    val in1 = readLine()
    val in2 = mutableListOf<String>()
    var line: String?
    line = readLine()
    while (line != null) {
        in2.add(line)
        line = readLine()
    }
    println(numbersGame(in1, in2))
}

/**
 * 数あてゲームの回答を返します。
 * @param turn ターン数
 * @param qaList 質問と回答
 */
fun numbersGame(@Suppress("UNUSED_PARAMETER") turn: String?,
                qaList: List<String>): String {
    // int型の配列を10個作る。初期値は0
    // 0:初期値、1:NO、2:YES
    val numAry = IntArray(10, { 0 })

    for (qa in qaList) {
        val sp = qa.split(" ")
        val qList = sp.take(sp.size - 1).map { it.toInt() }
        val a = sp[sp.size - 1]

        if (a == "NO") {

            for (q in qList) {
                numAry[q] = 1
            }
        }
        if (a == "YES") {
            // 0と2以外はすべて1
            for ((i, num) in numAry.withIndex()) {
                if ((num == 0 || num == 2) && qList.any { it == i }) {
                    numAry[i] = 2
                } else {
                    numAry[i] = 1
                }
            }
        }
    }

    // 結果を探す
    for ((i, num) in numAry.withIndex()) {
        if (num == 2) {
            return i.toString()
        }
    }
    for ((i, num) in numAry.withIndex()) {
        if (num == 0) {
            return i.toString()
        }
    }
    // ここには来ないはず
    return ""
}
0