結果

問題 No.82 市松模様
ユーザー hoho
提出日時 2020-07-30 15:46:18
言語 TypeScript
(5.4.3)
結果
AC  
実行時間 78 ms / 5,000 ms
コード長 828 bytes
コンパイル時間 7,711 ms
コンパイル使用メモリ 257,644 KB
実行使用メモリ 42,180 KB
最終ジャッジ日時 2023-09-17 05:03:41
合計ジャッジ時間 8,913 ms
ジャッジサーバーID
(参考情報)
judge11 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 77 ms
42,148 KB
testcase_01 AC 76 ms
42,164 KB
testcase_02 AC 77 ms
42,100 KB
testcase_03 AC 77 ms
42,024 KB
testcase_04 AC 77 ms
42,144 KB
testcase_05 AC 76 ms
42,180 KB
testcase_06 AC 75 ms
42,136 KB
testcase_07 AC 76 ms
42,140 KB
testcase_08 AC 78 ms
42,148 KB
testcase_09 AC 77 ms
42,176 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

const isEven = (n: number) => n % 2 == 0;

const writeRow = (n: number, o: string, t: string) => {
    let result = '';
    for (let i = 1; i <= n; i++) {
        if (isEven(i)) result += t;
        if (!isEven(i)) result += o;
    }
    return result
}

const Main = (input) => {
    const payload = input.split('\n');
    const data = payload[0].split(' ');
    const width: number = data[0], heigh: number = data[1];
    const start: string = data[2];
    const second: string = start === 'W' ? 'B' : 'W';
    let result = '';
    for (var i = 1; i <= heigh; i++) {
        if (!isEven(i)) result += writeRow(width, start, second);
        if (isEven(i)) result += writeRow(width, second, start);
        if (i < heigh) result += '\n';
    }
    console.log(result);
}

Main(require("fs").readFileSync("/dev/stdin", "utf8"));
0