結果

問題 No.82 市松模様
ユーザー yo-kondoyo-kondo
提出日時 2018-03-11 22:13:08
言語 Go
(1.22.1)
結果
AC  
実行時間 2 ms / 5,000 ms
コード長 962 bytes
コンパイル時間 10,595 ms
コンパイル使用メモリ 224,324 KB
実行使用メモリ 6,944 KB
最終ジャッジ日時 2024-04-23 01:15:28
合計ジャッジ時間 11,193 ms
ジャッジサーバーID
(参考情報)
judge2 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

package main

import (
	"bufio"
	"fmt"
	"os"
	"strconv"
	"strings"
)

// エントリポイント
func main() {
	in := bufio.NewScanner(os.Stdin)
	// 幅と高Hと左上の色
	in.Scan()
	input1 := in.Text()
	fmt.Println(checkeredPattern(input1))
}
func checkeredPattern(input string) string {
	sp := strings.Split(input, " ")
	width, _ := strconv.Atoi(sp[0])
	height, _ := strconv.Atoi(sp[1])
	// true="B",false="W"
	pattern := sp[2] == "B"
	// 文字列の結合はbyteスライスにappendするのが速いらしい
	rtnByte := make([]byte, 0)

	for i := 0; i < height; i++ {
		for j := 0; j < width; j++ {
			if pattern {
				rtnByte = append(rtnByte, "B"...)
			} else {
				rtnByte = append(rtnByte, "W"...)
			}
			pattern = !pattern
		}

		// 偶数の場合はpatternを反転
		if width%2 == 0 {
			pattern = !pattern
		}

		rtnByte = append(rtnByte, "\n"...)
	}
	// 最後の1バイト(改行)を削除
	return string(rtnByte[:len(rtnByte)-1])
}
0