結果

問題 No.721 Die tertia (ディエ・テルツィア)
ユーザー TomoProgTomoProg
提出日時 2018-10-17 20:07:17
言語 C#(csc)
(csc 3.9.0)
結果
AC  
実行時間 30 ms / 2,000 ms
コード長 2,689 bytes
コンパイル時間 844 ms
コンパイル使用メモリ 105,728 KB
実行使用メモリ 18,304 KB
最終ジャッジ日時 2024-04-20 20:46:32
合計ジャッジ時間 2,204 ms
ジャッジサーバーID
(参考情報)
judge2 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 28 ms
17,920 KB
testcase_01 AC 27 ms
18,304 KB
testcase_02 AC 28 ms
18,048 KB
testcase_03 AC 28 ms
18,048 KB
testcase_04 AC 28 ms
18,176 KB
testcase_05 AC 28 ms
18,048 KB
testcase_06 AC 28 ms
18,304 KB
testcase_07 AC 27 ms
18,048 KB
testcase_08 AC 29 ms
18,048 KB
testcase_09 AC 28 ms
18,048 KB
testcase_10 AC 28 ms
18,304 KB
testcase_11 AC 27 ms
18,048 KB
testcase_12 AC 29 ms
17,792 KB
testcase_13 AC 29 ms
17,920 KB
testcase_14 AC 30 ms
18,176 KB
testcase_15 AC 29 ms
18,176 KB
testcase_16 AC 28 ms
17,920 KB
testcase_17 AC 28 ms
17,792 KB
testcase_18 AC 29 ms
17,792 KB
testcase_19 AC 28 ms
18,176 KB
testcase_20 AC 27 ms
18,176 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
Microsoft (R) Visual C# Compiler version 3.9.0-6.21124.20 (db94f4cc)
Copyright (C) Microsoft Corporation. All rights reserved.

ソースコード

diff #

using System;
using System.Collections;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ConsoleApplication3
{
    public class Program
    {
        static void Main(string[] args)
        {
            new Program().Main2(Console.In, Console.Out);
        }

        public void Main2(TextReader reader, TextWriter writer)
        {
            var lastDays = new Dictionary<int, int>()   // 月ごとの最終日
            {
                { 1, 31 },
                { 2, 28 },
                { 3, 31 },
                { 4, 30 },
                { 5, 31 },
                { 6, 30 },
                { 7, 31 },
                { 8, 31 },
                { 9, 30 },
                { 10, 31 },
                { 11, 30 },
                { 12, 31 },
            };

            //-----------------------------
            // 初期入力
            //-----------------------------
            var date = reader.ReadLine().Split('/');
            var year = int.Parse(date[0]);
            var month = int.Parse(date[1]);
            var day = int.Parse(date[2]);

            //-----------------------------
            // うるう年の場合は29日に設定
            //-----------------------------
            if(CheckLeapYear(year))
            {
                lastDays[2] = 29;
            }


            //-----------------------------
            // メインロジック
            //-----------------------------
            day += 2;
            if (day > lastDays[month])
            {
                // 二日後、月をまたぐ場合は1月プラス
                day = day % lastDays[month];
                month++;
                if(month > 12)
                {
                    // 12月を超えた場合は1年プラス
                    month = month % 12;
                    year++;
                }
            }

            //-----------------------------
            // 結果確認
            //-----------------------------
            writer.WriteLine($"{year}/{month.ToString("D2")}/{day.ToString("D2")}");
        }

        /// <summary>
        /// うるう年判定
        /// </summary>
        /// <param name="year">年</param>
        /// <returns>true: うるう年 false: うるう年でない</returns>
        public bool CheckLeapYear(int year)
        {
            // 参考:http://tomoprog.hatenablog.com/entry/2016/03/01/004755
            if (year % 400 == 0) return true;
            if (year % 4 == 0 && year % 100 == 0) return false;
            if (year % 4 == 0) return true;
            return false;
        }

    }
}
0