Advertisement
Guest User

Untitled

a guest
Oct 17th, 2016
256
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.97 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Globalization;
  4. using System.Linq;
  5.  
  6. class Program
  7. {
  8.     static void Main()
  9.     {
  10.         string inputOne = Console.ReadLine();
  11.         string inputTwo = Console.ReadLine();
  12.  
  13.         DateTime startDate = DateTime.ParseExact(inputOne, "dd-MM-yyyy", CultureInfo.InvariantCulture);
  14.         DateTime endDate = DateTime.ParseExact(inputTwo, "dd-MM-yyyy", CultureInfo.InvariantCulture);
  15.  
  16.         //Holidays' months and days, ignore year
  17.         DateTime[] holidays = new DateTime[]
  18.             {
  19.         new DateTime(9999, 01, 01),
  20.         new DateTime(9999, 03, 01),
  21.         new DateTime(9999, 05, 01),
  22.         new DateTime(9999, 05, 06),
  23.         new DateTime(9999, 05, 24),
  24.         new DateTime(9999, 09, 06),
  25.         new DateTime(9999, 09, 22),
  26.         new DateTime(9999, 11, 01),
  27.         new DateTime(9999, 12, 24),
  28.         new DateTime(9999, 12, 25),
  29.         new DateTime(9999, 12, 26),
  30.             };
  31.  
  32.         //Get years here
  33.         List<DateTime> holidaysByYears = new List<DateTime>();
  34.         for (int i = 0; i < holidays.Length; i++)
  35.         {
  36.             int day = holidays[i].Day;
  37.             int month = holidays[i].Month;
  38.  
  39.             for (DateTime curDay = startDate; curDay <= endDate; curDay = curDay.AddDays(1))
  40.             {
  41.                 if (curDay.Day == day && curDay.Month == month)
  42.                 {
  43.                     holidaysByYears.Add(curDay);
  44.                 }
  45.             }
  46.         }
  47.  
  48.  
  49.         int workDays = 0;
  50.  
  51.         for (DateTime curDay = startDate; curDay <= endDate; curDay = curDay.AddDays(1))
  52.         {
  53.             bool holiday = holidaysByYears.Contains(curDay);
  54.             bool saturday = curDay.DayOfWeek == DayOfWeek.Saturday;
  55.             bool sunday = curDay.DayOfWeek == DayOfWeek.Sunday;
  56.  
  57.             if (!holiday && !saturday && !sunday)
  58.             {
  59.                 workDays++;
  60.             }
  61.         }
  62.  
  63.         Console.WriteLine(workDays);
  64.     }
  65. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement