結果

問題 No.82 市松模様
コンテスト
ユーザー yo-kondo
提出日時 2018-03-25 16:38:30
言語 Kotlin
(2.3.20)
コンパイル:
kotlinc _filename_ -include-runtime -d main.jar
実行:
kotlin main.jar
結果
AC  
実行時間 194 ms / 5,000 ms
コード長 859 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 8,689 ms
コンパイル使用メモリ 441,172 KB
実行使用メモリ 62,760 KB
最終ジャッジ日時 2026-05-14 17:25:52
合計ジャッジ時間 11,520 ms
ジャッジサーバーID
(参考情報)
judge1_1 / judge3_1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 7
権限があれば一括ダウンロードができます

ソースコード

diff #
raw source code

package yukicoder.no82

/**
 * エントリポイント
 */
fun main(args: Array<String>) {
    val in1 = readLine()
    print(checkeredPattern(in1))
}

/**
 * 幅、高さ、色をもとに市松模様を返します。最後に改行が入ります。
 * @param widthHeightColor 幅、高さ、色
 */
fun checkeredPattern(widthHeightColor: String?): String {
    if (widthHeightColor == null) {
        return ""
    }

    var pattern = ""
    val sp = widthHeightColor.split(" ")
    // true="B",false="W"
    var color = sp[2] == "B"
    for (h in 1..sp[1].toInt()) {
        for (w in 1..sp[0].toInt()) {
            pattern += if (color) "B" else "W"
            color = !color
        }

        // 偶数の場合は反転
        if (sp[0].toInt() % 2 == 0) {
            color = !color
        }
        pattern += "\n"
    }
    return pattern
}
0