結果
問題 | No.82 市松模様 |
ユーザー |
![]() |
提出日時 | 2018-05-16 10:59:56 |
言語 | Java (openjdk 23) |
結果 |
AC
|
実行時間 | 200 ms / 5,000 ms |
コード長 | 2,052 bytes |
コンパイル時間 | 3,677 ms |
コンパイル使用メモリ | 79,640 KB |
実行使用メモリ | 41,928 KB |
最終ジャッジ日時 | 2024-06-28 13:16:48 |
合計ジャッジ時間 | 5,900 ms |
ジャッジサーバーID (参考情報) |
judge3 / judge5 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 7 |
ソースコード
import java.util.Scanner;import java.util.InputMismatchException;import java.util.regex.Matcher;import java.util.regex.Pattern;public class CheckeredPattern {public static void main(String[] args){Scanner scanner = new Scanner(System.in);try{//入力と範囲が正しいかのチェックint Width = scanner.nextInt();int Height = scanner.nextInt();String Color = scanner.next();String AnotherColor = "";if(Width < 1 || Width > 50){System.out.println("Wは1≦W≦50の範囲で入力してください");System.exit(0);}if(Height < 1 || Height > 50){System.out.println("Hは1≦H≦50の範囲で入力してください");System.exit(0);}Pattern patternA = Pattern.compile(".*[^B W].*");Matcher matcherA = patternA.matcher(Color);if (matcherA.find()) {System.out.println("小文字アルファベットで入力してください");System.exit(0);}//AnotherColorの定義if(Color.equals("B")){AnotherColor += "W";}else{AnotherColor += "B";}//必要回数のループ処理for(int i = 0 ; i < Height ; i++){for(int j = 0 ; j < Width ; j++){if((i + j) % 2 == 0 ){System.out.print(Color);}else{System.out.print(AnotherColor);}}//Width回のループ後の改行System.out.println(" ");}}catch(InputMismatchException e){System.out.println("数値で入力してください");}catch(Exception E){System.out.println("想定外のエラーです");}}}