Advertisement
DaniPasteBin

Untitled

Jun 18th, 2018
80
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.87 KB | None | 0 0
  1. using System;
  2. using System.Globalization;
  3.  
  4. namespace _01.CountWorkingDaYS
  5. {
  6.     class Program
  7.     {
  8.         static void Main(string[] args)
  9.         {
  10.             string startDateStr = Console.ReadLine();
  11.             string endDateStr = Console.ReadLine();
  12.             DateTime startDate = DateTime.ParseExact(startDateStr, "dd-MM-yyyy",CultureInfo.InvariantCulture);
  13.             DateTime endDate = DateTime.ParseExact(endDateStr, "dd-MM-yyyy", CultureInfo.InvariantCulture);
  14.  
  15.             DateTime[] nonWorking = new DateTime[]   //[11] //{DateTime.ParseExact("") };
  16.             {
  17.                 new DateTime(4,01,01),  //пълня масив с неработните празници
  18.                 new DateTime(4,03,03),
  19.                 new DateTime(4,05,01),
  20.                 new DateTime(4,05,06),
  21.                 new DateTime(4,05,24),
  22.                 new DateTime(4,09,06),
  23.                 new DateTime(4,09,22),
  24.                 new DateTime(4,11,01),
  25.                 new DateTime(4,12,24),
  26.                 new DateTime(4,12,25),
  27.                 new DateTime(4,12,26)
  28.             };
  29.  
  30.             int countWorkDays = 0;
  31.  
  32.             for (DateTime i = startDate; i <= endDate; i=i.AddDays(1))
  33.             {
  34.                 if (!(i.DayOfWeek == DayOfWeek.Saturday) && !(i.DayOfWeek == DayOfWeek.Sunday))
  35.                 {
  36.                     countWorkDays++;
  37.                     foreach (var item in nonWorking)
  38.                     {
  39.                         if ((i.Day == item.Day) && (i.Month == item.Month))
  40.                         {
  41.                             countWorkDays--;
  42.                         }
  43.                     }
  44.                 }
  45.  
  46.                
  47.             }
  48.             Console.WriteLine(countWorkDays);
  49.  
  50.             /*for (int i = 0; i < nonWorking.Length; i++)
  51.             {
  52.             }*/
  53.            
  54.  
  55.  
  56.  
  57.         }
  58.     }
  59. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement