結果

問題 No.82 市松模様
ユーザー yo-kondoyo-kondo
提出日時 2019-04-13 12:13:32
言語 Rust
(1.72.1)
結果
AC  
実行時間 1 ms / 5,000 ms
コード長 1,173 bytes
コンパイル時間 1,308 ms
コンパイル使用メモリ 142,712 KB
実行使用メモリ 4,352 KB
最終ジャッジ日時 2023-10-13 10:47:20
合計ジャッジ時間 2,145 ms
ジャッジサーバーID
(参考情報)
judge13 / judge14
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,348 KB
testcase_01 AC 1 ms
4,352 KB
testcase_02 AC 1 ms
4,348 KB
testcase_03 AC 1 ms
4,348 KB
testcase_04 AC 1 ms
4,348 KB
testcase_05 AC 1 ms
4,348 KB
testcase_06 AC 1 ms
4,352 KB
testcase_07 AC 1 ms
4,348 KB
testcase_08 AC 1 ms
4,348 KB
testcase_09 AC 1 ms
4,348 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

use std::io::stdin;

/// エントリポイント
fn main() {
    let input = read_lines();
    println!("{}", checkered_pattern(input));
}

/// 標準入力から文字列を取得します。
fn read_lines() -> String {
    // 1行目
    let mut str1 = String::new();
    stdin().read_line(&mut str1).unwrap();
    str1
}

/// 市松模様の文字列を返します。
fn checkered_pattern(input: String) -> String {
    let sp = input.trim().split_whitespace().collect::<Vec<&str>>();
    let width = sp[0].parse::<i32>().unwrap();
    let height = sp[1].parse::<i32>().unwrap();
    let mut color = sp[2];

    let mut pattern = String::new();
    for _i in 0..height {
        for _i in 0..width {
            if color == "B" {
                pattern += "B";
                color = "W";
            } else {
                pattern += "W";
                color = "B";
            }
        }
        pattern += "\n";

        // TODO: 幅が偶数の場合は反転
        if width % 2 == 0 {
            if color == "W" {
                color = "B"
            } else {
                color = "W"
            }
        }
    }
    pattern.trim().to_string()
}
0