stkirov

05.NumberOfWorkDatesBetweenDates

Jan 27th, 2013
108
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.34 KB | None | 0 0
  1. using System;
  2. class NumberOfWorkDatesBetweenDates
  3. {
  4.     static bool IsHoliday(DateTime day, DateTime[] holidays)
  5.     {
  6.         foreach (DateTime holiday in holidays)
  7.         {
  8.             if (day == holiday)
  9.             {
  10.                 return true;
  11.             }
  12.         }
  13.         return false;
  14.     }
  15.  
  16.     static void Main()
  17.     {
  18.         DateTime endDate = DateTime.Parse(Console.ReadLine());
  19.         DateTime today = DateTime.Today;
  20.         int days = 0;
  21.         DateTime[] holidays = new DateTime[]
  22.         {
  23.             new DateTime(today.Year, 1, 1),
  24.             new DateTime(today.Year, 3, 3),
  25.             new DateTime(today.Year, 5, 1),
  26.             new DateTime(today.Year, 5, 2),
  27.             new DateTime(today.Year, 5, 6),
  28.             new DateTime(today.Year, 5, 24),
  29.             new DateTime(today.Year, 9, 22),
  30.             new DateTime(today.Year, 12, 24),
  31.             new DateTime(today.Year, 12, 25),
  32.             new DateTime(today.Year, 12, 26),
  33.             new DateTime(today.Year, 12, 31)
  34.         };
  35.  
  36.         while (today<endDate)
  37.         {
  38.             if (today.DayOfWeek != DayOfWeek.Saturday && today.DayOfWeek != DayOfWeek.Sunday && !IsHoliday(today, holidays))
  39.             {
  40.                 days++;
  41.             }
  42.             today = today.AddDays(1);
  43.         }
  44.         Console.WriteLine(days);
  45.     }
  46. }
Advertisement
Add Comment
Please, Sign In to add comment