結果

問題 No.70 睡眠の重要性!
ユーザー 明智重蔵明智重蔵
提出日時 2015-08-08 05:36:42
言語 C#(csc)
(csc 3.9.0)
結果
AC  
実行時間 61 ms / 5,000 ms
コード長 2,791 bytes
コンパイル時間 2,191 ms
コンパイル使用メモリ 107,848 KB
実行使用メモリ 23,812 KB
最終ジャッジ日時 2023-09-25 07:00:24
合計ジャッジ時間 3,213 ms
ジャッジサーバーID
(参考情報)
judge13 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 59 ms
21,696 KB
testcase_01 AC 61 ms
23,812 KB
testcase_02 AC 61 ms
21,888 KB
testcase_03 AC 61 ms
21,912 KB
testcase_04 AC 61 ms
21,884 KB
testcase_05 AC 60 ms
21,756 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.Generic;
using System.Linq;

class Program
{
    static string InputPattern = "Input3";

    static List<string> GetInputList()
    {
        var WillReturn = new List<string>();

        if (InputPattern == "Input1") {
            WillReturn.Add("3");
            WillReturn.Add("22:24 5:9");
            WillReturn.Add("22:46 5:37");
            WillReturn.Add("1:11 7:11");
            //1176
            //それぞれ、6時間45分 / 6時間51分 / 6時間0分の睡眠なので、
            //合計で19時間36分です。
            //これを分単位に直すと1176分となります。
        }
        else if (InputPattern == "Input2") {
            WillReturn.Add("5");
            WillReturn.Add("22:30 4:30");
            WillReturn.Add("22:46 4:46");
            WillReturn.Add("1:17 7:26");
            WillReturn.Add("0:38 7:0");
            WillReturn.Add("23:49 7:41");
            //1943
        }
        else {
            string wkStr;
            while ((wkStr = Console.ReadLine()) != null) WillReturn.Add(wkStr);
        }
        return WillReturn;
    }

    struct PairTimeDef
    {
        internal int StaH;
        internal int StaM;
        internal int EndH;
        internal int EndM;
    }

    static void Main()
    {
        List<string> InputList = GetInputList();
        var PairTimeList = new List<PairTimeDef>();
        foreach (string EachStr in InputList.Skip(1)) {
            string[] wkArr = EachStr.Split(' ', ':');
            PairTimeDef WillAdd;
            WillAdd.StaH = int.Parse(wkArr[0]);
            WillAdd.StaM = int.Parse(wkArr[1]);
            WillAdd.EndH = int.Parse(wkArr[2]);
            WillAdd.EndM = int.Parse(wkArr[3]);
            PairTimeList.Add(WillAdd);
        }
        Console.WriteLine(DeriveSum(PairTimeList));
    }

    //合計睡眠時間を求める
    static int DeriveSum(List<PairTimeDef> pPairTimeList)
    {
        int WillReturn = 0;

        foreach (PairTimeDef EachPairTime in pPairTimeList) {
            int StaKeikaMinute = DeriveKeikaMinute(EachPairTime.StaH, EachPairTime.StaM);
            int EndKeikaMinute = DeriveKeikaMinute(EachPairTime.EndH, EachPairTime.EndM);

            //Sta <= End の場合は、24時をまたいでいない
            if (StaKeikaMinute <= EndKeikaMinute) {
                WillReturn += EndKeikaMinute - StaKeikaMinute;
                continue;
            }
            //Sta > End の場合は、24時をまたいだ対応
            WillReturn += 24 * 60 - StaKeikaMinute;
            WillReturn += EndKeikaMinute;
        }
        return WillReturn;
    }

    //0時0分からの経過分数を求める
    static int DeriveKeikaMinute(int pH, int pM)
    {
        return pH * 60 + pM;
    }
}
0