yukicoder No.82 市松模様

Problem

No.82 市松模様 - yukicoder

Solution

Code

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.time.format.DateTimeFormatter;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;

public class Main {

    public static void main(String[] args) throws IOException {
        BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
        String[] inputs = reader.readLine().split(" ");
        int W = Integer.parseInt(inputs[0]);
        int H = Integer.parseInt(inputs[1]);
        String C = inputs[2];


        for (int i = 0; i < H; i++) {
            String leftMostPattern;
            if (i % 2 == 0) {
                leftMostPattern = C;
            } else {
                leftMostPattern = nextPattern(C);
            }
            StringBuilder builder = new StringBuilder(leftMostPattern);
            for (int j = 1; j < W; j++) {
                leftMostPattern = nextPattern(leftMostPattern);
                builder.append(leftMostPattern);
            }
            System.out.println(builder.toString());
        }
    }

    private static String nextPattern(String currentPattern) {
        if (currentPattern.equals("B")) {
            return "W";
        } else {
            return "B";
        }
    }


}
Remove all ads