結果

問題 No.82 市松模様
ユーザー YukimotoPGYukimotoPG
提出日時 2019-02-14 22:20:20
言語 Java21
(openjdk 21)
結果
AC  
実行時間 130 ms / 5,000 ms
コード長 843 bytes
コンパイル時間 2,115 ms
コンパイル使用メモリ 74,244 KB
実行使用メモリ 56,176 KB
最終ジャッジ日時 2023-10-11 12:46:05
合計ジャッジ時間 4,378 ms
ジャッジサーバーID
(参考情報)
judge12 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 125 ms
55,928 KB
testcase_01 AC 126 ms
55,984 KB
testcase_02 AC 125 ms
55,768 KB
testcase_03 AC 123 ms
55,560 KB
testcase_04 AC 130 ms
56,028 KB
testcase_05 AC 126 ms
56,176 KB
testcase_06 AC 126 ms
55,564 KB
testcase_07 AC 127 ms
55,624 KB
testcase_08 AC 129 ms
56,088 KB
testcase_09 AC 127 ms
55,804 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.util.*;

class Main {
	static Scanner sc = new Scanner(System.in);
	public static void main(String[] args) {
		
		int w = sc.nextInt(); int h = sc.nextInt();
		char upLeft = sc.next().charAt(0);
		
		for (int i=0; i<h; i++) {
			if (upLeft == 'B') {
				if (i%2 == 0) System.out.println(bwbw(w));
				else System.out.println(wbwb(w));
			}
			else {
				if (i%2 == 0) System.out.println(wbwb(w));
				else System.out.println(bwbw(w));
			}
		}
		
	}
	
	static String bwbw(int n) {
		StringBuilder sb = new StringBuilder();
		for (int i=0; i<n; i++) {
			if (i%2 == 0) sb.append("B");
			else sb.append("W");
		}
		return sb.toString();
	}
	static String wbwb(int n) {
		StringBuilder sb = new StringBuilder();
		for (int i=0; i<n; i++) {
			if (i%2 == 0) sb.append("W");
			else sb.append("B");
		}
		return sb.toString();
	}
	
	
}
0