結果

問題 No.522 Make Test Cases(テストケースを作る)
ユーザー nihi9119nihi9119
提出日時 2017-06-15 17:12:01
言語 Java21
(openjdk 21)
結果
AC  
実行時間 1,797 ms / 2,000 ms
コード長 1,887 bytes
コンパイル時間 6,507 ms
コンパイル使用メモリ 82,768 KB
実行使用メモリ 51,416 KB
最終ジャッジ日時 2023-10-25 06:58:25
合計ジャッジ時間 12,519 ms
ジャッジサーバーID
(参考情報)
judge14 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 210 ms
41,208 KB
testcase_01 AC 307 ms
45,332 KB
testcase_02 AC 283 ms
43,220 KB
testcase_03 AC 434 ms
49,640 KB
testcase_04 AC 88 ms
38,204 KB
testcase_05 AC 87 ms
39,720 KB
testcase_06 AC 86 ms
38,216 KB
testcase_07 AC 99 ms
39,888 KB
testcase_08 AC 143 ms
40,588 KB
testcase_09 AC 375 ms
48,524 KB
testcase_10 AC 1,797 ms
51,416 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

package test7;

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

/**
 * No.522 Make Test Cases(テストケースを作る)
 * http://yukicoder.me/problems/no/522
 *
 * hさんは以下の制約に基づきテストケースを作成するようお願いされました。
 * a+b+c=Nかつa≤b≤c(ただしa,b,c,Nは正整数)
 * 考えられるテストケースをすべて、
 * ・aが小さい順に
 * ・aが同じならbが小さい順に
 * 求めてください。
 */

public class Question_21_0615 {

	final static int MIN = 3;
	final static int MAX = 3000;

	public static void main(String[] args) {
		InputStreamReader re = new InputStreamReader(System.in);
		BufferedReader br = new BufferedReader(re);

		try {
			int inputNum = Integer.parseInt(br.readLine());
			if (NumJudg(inputNum, MIN, MAX)) {
				for(int a = 1; a <= inputNum; a++){
					for(int b = a; a + b <= inputNum; b++){
						final int c = inputNum - a - b;
						if(c < b){ break; }
						System.out.println(a + " " + b + " " + c);
					}
				}
			} 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;
	}
}
0