Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.Globalization;
- using System.Linq;
- class Program
- {
- static void Main()
- {
- string inputOne = Console.ReadLine();
- string inputTwo = Console.ReadLine();
- DateTime startDate = DateTime.ParseExact(inputOne, "dd-MM-yyyy", CultureInfo.InvariantCulture);
- DateTime endDate = DateTime.ParseExact(inputTwo, "dd-MM-yyyy", CultureInfo.InvariantCulture);
- //Holidays' months and days, ignore year
- DateTime[] holidays = new DateTime[]
- {
- new DateTime(9999, 01, 01),
- new DateTime(9999, 03, 01),
- new DateTime(9999, 05, 01),
- new DateTime(9999, 05, 06),
- new DateTime(9999, 05, 24),
- new DateTime(9999, 09, 06),
- new DateTime(9999, 09, 22),
- new DateTime(9999, 11, 01),
- new DateTime(9999, 12, 24),
- new DateTime(9999, 12, 25),
- new DateTime(9999, 12, 26),
- };
- //Get years here
- List<DateTime> holidaysByYears = new List<DateTime>();
- for (int i = 0; i < holidays.Length; i++)
- {
- int day = holidays[i].Day;
- int month = holidays[i].Month;
- for (DateTime curDay = startDate; curDay <= endDate; curDay = curDay.AddDays(1))
- {
- if (curDay.Day == day && curDay.Month == month)
- {
- holidaysByYears.Add(curDay);
- }
- }
- }
- int workDays = 0;
- for (DateTime curDay = startDate; curDay <= endDate; curDay = curDay.AddDays(1))
- {
- bool holiday = holidaysByYears.Contains(curDay);
- bool saturday = curDay.DayOfWeek == DayOfWeek.Saturday;
- bool sunday = curDay.DayOfWeek == DayOfWeek.Sunday;
- if (!holiday && !saturday && !sunday)
- {
- workDays++;
- }
- }
- Console.WriteLine(workDays);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement