結果

問題 No.207 世界のなんとか
ユーザー nihi9119nihi9119
提出日時 2017-06-07 19:16:27
言語 Java21
(openjdk 21)
結果
AC  
実行時間 59 ms / 5,000 ms
コード長 2,634 bytes
コンパイル時間 4,642 ms
コンパイル使用メモリ 77,796 KB
実行使用メモリ 53,580 KB
最終ジャッジ日時 2023-10-23 18:59:38
合計ジャッジ時間 5,496 ms
ジャッジサーバーID
(参考情報)
judge12 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 54 ms
53,580 KB
testcase_01 AC 53 ms
53,564 KB
testcase_02 AC 56 ms
53,572 KB
testcase_03 AC 55 ms
53,572 KB
testcase_04 AC 56 ms
52,636 KB
testcase_05 AC 55 ms
52,612 KB
testcase_06 AC 53 ms
53,504 KB
testcase_07 AC 54 ms
53,560 KB
testcase_08 AC 54 ms
52,648 KB
testcase_09 AC 54 ms
52,600 KB
testcase_10 AC 54 ms
51,528 KB
testcase_11 AC 54 ms
53,568 KB
testcase_12 AC 56 ms
52,652 KB
testcase_13 AC 57 ms
53,568 KB
testcase_14 AC 56 ms
53,576 KB
testcase_15 AC 59 ms
53,568 KB
testcase_16 AC 56 ms
53,564 KB
testcase_17 AC 54 ms
52,644 KB
testcase_18 AC 55 ms
52,628 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

package test_5;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.ArrayList;

/**
 * A以上B以下の整数のうち、3の倍数および3の付く数を、小さい順に出力してください。
 * なお、「3の付く数」とは、10進数表記にした時、少なくとも1つの桁が3であるような数のことです。
 */

public class Question_13_0607_1 {

	static final int FIRST_MIN = 1;
	static final int SECONTD_MIN = 1;
	static final int DIFF_MIN = 0; // 差分 difference
	static final int FIRST_MAX = 2000000000;
	static final int SECONTD_MAX = 2000000000;
	static final int DIFF_MAX = 100;

	public static void main(String[] args) {

		InputStreamReader re = new InputStreamReader(System.in);
		BufferedReader br = new BufferedReader(re);
		ArrayList<Integer> resultList = new ArrayList<Integer>();

		try {
			String[] input = br.readLine().split(" ");
			int firstNum = Integer.parseInt(input[0]);
			int secondNum = Integer.parseInt(input[1]);
			int diffNum = secondNum - firstNum;

			// 入力値判定
			if (NumJudg(firstNum, FIRST_MIN, FIRST_MAX) && NumJudg(secondNum, SECONTD_MIN, SECONTD_MAX)
					&& NumJudg(diffNum, DIFF_MIN, DIFF_MAX)) {

				// 数値チェック
				for (int i = firstNum; i <= secondNum; i++) {
					if (i % 3 == 0) {
						resultList.add(i);
					} else if (threeJudg(i)) {
						resultList.add(i);
					}
				}

				// 表示
				for (int num : resultList) {
					System.out.println(num);
				}

			} else {
				System.out.println("入力値が有効範囲外です");
			}

		} catch (NumberFormatException e) {
			System.out.println("数字を入力して下さい。");
		} catch (IOException e) {
			System.out.println("エラーが発生しました。");
		} finally {
			try {
				re.close();
				br.close();
			} catch (IOException e) {
				System.out.println("InputStreamReader、BufferedReaderクローズ中にエラーが発生しました");
			}
		}
	}

	/**
	 * 有効値判定
	 * @param input 判定するもの
	 * @param max 最大値
	 * @param min 最小値
	 * @return 範囲内ならtrue,範囲外ならfalseを返す
	 */
	private static boolean NumJudg(int input, int min, int max) {
		Boolean result = false;
		if (min <= input && input <= max) {
			result = true;
		}
		return result;
	}

	/**
	 * 有効値判定
	 * @param input 判定するもの
	 * @return 3を含むならTrueを返す
	 */
	private static boolean threeJudg(int input) {
		Boolean result = false;
		String str = String.valueOf(input);
		if (str.contains("3")) {
			result = true;
		}
		return result;
	}

}
0