結果

問題 No.82 市松模様
ユーザー ゆうPゆうP
提出日時 2024-03-30 14:49:01
言語 Go
(1.22.1)
結果
AC  
実行時間 2 ms / 5,000 ms
コード長 618 bytes
コンパイル時間 13,192 ms
コンパイル使用メモリ 212,052 KB
実行使用メモリ 6,676 KB
最終ジャッジ日時 2024-03-30 14:49:15
合計ジャッジ時間 13,617 ms
ジャッジサーバーID
(参考情報)
judge12 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

// No.82 市松模様
package main

import (
	"fmt"
	"strings"
)

func main() {
	const black = "B"
	const white = "W"

	var w, h int
	var c string
	fmt.Scan(&w, &h, &c)

	var pair1, pair2 string
	if c == black {
		pair1 = black + white
		pair2 = white + black
	} else {
		pair1 = white + black
		pair2 = black + white
	}

	var line string
	for i := 0; i < h; i++ {
		// 模様の決定
		if i%2 == 0 {
			line = pair1
		} else {
			line = pair2
		}
		// 列数の決定
		if w%2 == 0 {
			fmt.Println(strings.Repeat(line, int(w/2)))
		} else {
			fmt.Println(strings.Repeat(line, int(w/2)) + string(line[0]))
		}
	}
}
0