結果

問題 No.296 n度寝
ユーザー nihi9119nihi9119
提出日時 2017-06-08 18:04:40
言語 Java21
(openjdk 21)
結果
AC  
実行時間 71 ms / 1,000 ms
コード長 2,694 bytes
コンパイル時間 3,902 ms
コンパイル使用メモリ 77,568 KB
実行使用メモリ 54,692 KB
最終ジャッジ日時 2023-10-23 19:52:02
合計ジャッジ時間 5,708 ms
ジャッジサーバーID
(参考情報)
judge15 / judge13
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 67 ms
52,656 KB
testcase_01 AC 56 ms
53,596 KB
testcase_02 AC 53 ms
53,592 KB
testcase_03 AC 52 ms
53,584 KB
testcase_04 AC 52 ms
53,592 KB
testcase_05 AC 52 ms
53,588 KB
testcase_06 AC 51 ms
53,588 KB
testcase_07 AC 67 ms
54,684 KB
testcase_08 AC 71 ms
54,692 KB
testcase_09 AC 52 ms
53,592 KB
testcase_10 AC 51 ms
53,592 KB
testcase_11 AC 53 ms
53,588 KB
testcase_12 AC 51 ms
51,572 KB
testcase_13 AC 53 ms
53,588 KB
testcase_14 AC 54 ms
53,596 KB
testcase_15 AC 53 ms
53,592 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

package test_5;

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

/**
 * No.296 n度寝 http://yukicoder.me/problems/no/296
 * 目覚まし時計のアラームが最初に鳴る時刻と、それ以降にアラームが鳴る間隔が与えられたとき、
 * ユキさんがn度寝するとして、ユキさんが最終的に起床する時刻を求めてください。
 */

public class Question_14_0608 {

	static final int SLEEP_MIN = 1;
	static final int HOUR_MIN = 0;
	static final int MINUTE_MIN = 0;
	static final int INTERVAL_MIN = 1;
	static final int SLEEP_MAX = (int)Math.pow(10, 9);
	static final int HOUR_MAX = 23;
	static final int MINUTE_MAX = 59;
	static final int INTERVAL_MAX = 1440; // 24*60

	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 sleepNum = Integer.parseInt(input[0]);
			int hour = Integer.parseInt(input[1]);
			int minute = Integer.parseInt(input[2]);
			int interval = Integer.parseInt(input[3]);

			//有効値チェック
			if (NumJudg(sleepNum, SLEEP_MIN, SLEEP_MAX)
					&& NumJudg(hour, HOUR_MIN, HOUR_MAX)
					&& NumJudg(minute, MINUTE_MIN, MINUTE_MAX)
					&& NumJudg(interval, INTERVAL_MIN, INTERVAL_MAX)) {

				//最終起床時間 分単位
				int sumMin = 0;
				//起床するまでの合計(分)
				for (int i = 0; i < sleepNum - 1; i++) {
					sumMin += interval;
				}
				sumMin += hour * 60 + minute;

				//起床時間
				int resultHour = sumMin / 60;
				if (resultHour > HOUR_MAX) {
					resultHour = resultHour % 24;
				}
				System.out.println(resultHour); //時間
				System.out.println(sumMin % 60); //分

			} 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