結果
問題 | No.82 市松模様 |
ユーザー | SagToki |
提出日時 | 2018-05-16 10:59:56 |
言語 | Java21 (openjdk 21) |
結果 |
AC
|
実行時間 | 188 ms / 5,000 ms |
コード長 | 2,052 bytes |
コンパイル時間 | 3,854 ms |
コンパイル使用メモリ | 76,332 KB |
実行使用メモリ | 56,260 KB |
最終ジャッジ日時 | 2023-09-10 22:16:50 |
合計ジャッジ時間 | 6,273 ms |
ジャッジサーバーID (参考情報) |
judge14 / judge13 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 129 ms
55,628 KB |
testcase_01 | AC | 128 ms
53,780 KB |
testcase_02 | AC | 127 ms
55,764 KB |
testcase_03 | AC | 128 ms
55,792 KB |
testcase_04 | AC | 133 ms
55,620 KB |
testcase_05 | AC | 133 ms
55,724 KB |
testcase_06 | AC | 140 ms
55,860 KB |
testcase_07 | AC | 153 ms
56,260 KB |
testcase_08 | AC | 176 ms
56,000 KB |
testcase_09 | AC | 188 ms
55,980 KB |
ソースコード
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("想定外のエラーです"); } } }