結果
問題 |
No.82 市松模様
|
ユーザー |
|
提出日時 | 2018-03-11 22:13:08 |
言語 | Go (1.23.4) |
結果 |
AC
|
実行時間 | 2 ms / 5,000 ms |
コード長 | 962 bytes |
コンパイル時間 | 12,027 ms |
コンパイル使用メモリ | 222,476 KB |
実行使用メモリ | 6,820 KB |
最終ジャッジ日時 | 2024-10-15 00:28:50 |
合計ジャッジ時間 | 12,785 ms |
ジャッジサーバーID (参考情報) |
judge2 / judge5 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 7 |
ソースコード
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]) }