AtCoderのPAST    次のPASTの問題へ    前のPASTの問題へ

第11回PAST J 完全週休二日制


問題へのリンク


C#のソース

using System;
using System.Collections.Generic;
using System.Linq;

class Program
{
    static string InputPattern = "InputX";

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

        if (InputPattern == "Input1") {
            WillReturn.Add("2022-01-01");
            WillReturn.Add("2022-01-08");
            //3
        }
        else if (InputPattern == "Input2") {
            WillReturn.Add("2024-02-26");
            WillReturn.Add("2024-03-02");
            //1
        }
        else if (InputPattern == "Input3") {
            WillReturn.Add("2022-01-01");
            WillReturn.Add("9999-12-31");
            //832544
        }
        else {
            string wkStr;
            while ((wkStr = Console.ReadLine()) != null) WillReturn.Add(wkStr);
        }
        return WillReturn;
    }

    static void Main()
    {
        List<string> InputList = GetInputList();
        string S = InputList[0];
        string T = InputList[1];

        DateTime CurrDate = DateTime.ParseExact(S, @"yyyy-MM-dd", null);
        DateTime EndDate = DateTime.ParseExact(T, @"yyyy-MM-dd", null);

        int Answer = 0;
        while (true) {
            if (CurrDate.DayOfWeek == DayOfWeek.Saturday) Answer++;
            if (CurrDate.DayOfWeek == DayOfWeek.Sunday) Answer++;

            if (CurrDate == EndDate) {
                break;
            }
            else {
                CurrDate += new TimeSpan(1, 0, 0, 0);
            }
        }
        Console.WriteLine(Answer);
    }
}


解説

365*8000 = 2920000
なので、DateTime型でナイーブに求めてます。