結果

問題 No.721 Die tertia (ディエ・テルツィア)
ユーザー yoneoka1985yoneoka1985
提出日時 2018-10-10 22:32:05
言語 Java21
(openjdk 21)
結果
AC  
実行時間 126 ms / 2,000 ms
コード長 1,781 bytes
コンパイル時間 3,689 ms
コンパイル使用メモリ 79,520 KB
実行使用メモリ 41,320 KB
最終ジャッジ日時 2024-04-20 19:31:56
合計ジャッジ時間 7,028 ms
ジャッジサーバーID
(参考情報)
judge4 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 119 ms
40,308 KB
testcase_01 AC 125 ms
41,080 KB
testcase_02 AC 120 ms
40,896 KB
testcase_03 AC 124 ms
41,320 KB
testcase_04 AC 113 ms
40,860 KB
testcase_05 AC 110 ms
40,212 KB
testcase_06 AC 124 ms
41,180 KB
testcase_07 AC 124 ms
41,180 KB
testcase_08 AC 125 ms
41,140 KB
testcase_09 AC 116 ms
40,400 KB
testcase_10 AC 126 ms
41,248 KB
testcase_11 AC 124 ms
40,564 KB
testcase_12 AC 114 ms
40,728 KB
testcase_13 AC 115 ms
40,628 KB
testcase_14 AC 118 ms
40,624 KB
testcase_15 AC 114 ms
40,076 KB
testcase_16 AC 115 ms
39,584 KB
testcase_17 AC 122 ms
41,084 KB
testcase_18 AC 113 ms
40,228 KB
testcase_19 AC 114 ms
40,032 KB
testcase_20 AC 111 ms
40,424 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

package yukicoder;

import java.util.HashMap;
import java.util.Map;
import java.util.Map.Entry;
import java.util.Scanner;
import java.util.Set;

public class DieTeria {

	static Map<Integer, Integer> lastDay = new HashMap<Integer, Integer>() {
		{
			put(1, 31);
			put(2, 28);
			put(3, 31);
			put(4, 30);
			put(5, 31);
			put(6, 30);
			put(7, 31);
			put(8, 31);
			put(9, 30);
			put(10, 31);
			put(11, 30);
			put(12, 31);
		}
	};

	// 日付をn日後に進める。
	static int n = 2;

	public static void main(String[] args) {
		// 標準入力から読み込む際に、Scannerオブジェクトを使う。
		Scanner sc = new Scanner(System.in);

		String s = sc.next();
		int year = Integer.parseInt(s.split("/")[0]);
		int month = Integer.parseInt(s.split("/")[1]);
		int day = Integer.parseInt(s.split("/")[2]);

//		 int year = 2001;
//		 int month = 2;
//		 int day = 27;

		if (isUruu(year)) {
			lastDay.put(2, 29);
		}
		

		if (isOverEndOfMonth(month, day + n)) {
			day = reCalucurateDay(month, day + n);
			if (isOverEndOfYear(year, month + 1)) {
				month = reCalucurateMonth(month);
				year++;
			} else {
				month++;
			}
		} else {
			day += n;
		}

		System.out.println(String.format("%04d/%02d/%02d", year, month, day));
	}

	static boolean isUruu(int year) {

		if (year % 400 == 0) {
			return true;
		} else if (year % 100 == 0) {
			return false;
		} else if (year % 4 == 0) {
			return true;
		}

		return false;
	}

	static int reCalucurateDay(int month, int day) {
		return day - lastDay.get(month);
	}

	static int reCalucurateMonth(int month) {
		return 1;
	}

	static boolean isOverEndOfMonth(int month, int day) {
		return (day > lastDay.get(month));
	}

	static boolean isOverEndOfYear(int year, int month) {
		return (month > 12);
	}

}
0