結果

問題 No.82 市松模様
ユーザー tsunabittsunabit
提出日時 2018-04-29 18:44:24
言語 Java19
(openjdk 21)
結果
AC  
実行時間 175 ms / 5,000 ms
コード長 1,614 bytes
コンパイル時間 3,588 ms
コンパイル使用メモリ 71,892 KB
実行使用メモリ 56,140 KB
最終ジャッジ日時 2023-09-10 08:06:08
合計ジャッジ時間 5,811 ms
ジャッジサーバーID
(参考情報)
judge13 / judge14
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 124 ms
55,860 KB
testcase_01 AC 127 ms
56,140 KB
testcase_02 AC 124 ms
55,588 KB
testcase_03 AC 125 ms
56,116 KB
testcase_04 AC 130 ms
55,340 KB
testcase_05 AC 129 ms
55,856 KB
testcase_06 AC 134 ms
55,676 KB
testcase_07 AC 164 ms
55,804 KB
testcase_08 AC 175 ms
55,688 KB
testcase_09 AC 172 ms
55,704 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.util.Scanner;

// ***問題文***
// 幅Wと高さHと左上の色が指定されるので市松模様を描け。
// 市松模様は、黒と白が交互に現れる模様である。
// 模様は黒を'B'、白を'W'を使って描くものとする。
// 詳しくはサンプルを見てください。
// ***入力***
// W H C
// 幅Wと高さHと左上の色Cの3つの情報が与えられる。
// W,Hは1以上50以下の整数。(1<=W,H<=50)
// Cは'B'か'W'のどちらかである。
// ***出力***
// 市松模様を描け。最後の行にも改行を忘れずに。

public class No82 {
    public static void main(String[] args) {
        // 標準入力から読み込む際に、Scannerオブジェクトを使う。
        Scanner sc = new Scanner(System.in);
        int w = sc.nextInt();
        int h = sc.nextInt();
        String c = sc.next();
        String o = "";

        if("B".equals(c)) {
            o = "W";
        }else {
            o = "B";
        }

        for(int i = 0; i < h; i++) {
            for(int j = 0; j < w; j++) {
                if(i % 2 == 0) {
                    if(j % 2 == 0) {
                        System.out.print(c);
                    }else {
                        System.out.print(o);
                    }
                }else {
                    if(j % 2 == 0) {
                        System.out.print(o);
                    }else {
                        System.out.print(c);
                    }
                }
            }
            System.out.println("");
        }
        // System.out.println("");
    }
}
0