Advertisement
Guest User

Untitled

a guest
Oct 14th, 2016
228
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.83 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Globalization;
  4. using System.Linq;
  5. using System.Text;
  6. using System.Threading.Tasks;
  7.  
  8. namespace CountWorkingDays
  9. {
  10. class CountWorkingDays
  11. {
  12. static void Main(string[] args)
  13. {
  14. string firstDate = Console.ReadLine();
  15. string secondDate = Console.ReadLine();
  16.  
  17. DateTime startDate = DateTime.ParseExact(firstDate, "dd-MM-yyyy", CultureInfo.InvariantCulture);
  18. DateTime endDate = DateTime.ParseExact(secondDate, "dd-MM-yyyy", CultureInfo.InvariantCulture);
  19.  
  20. List<DateTime> holidays = new List<DateTime>();
  21. holidays.Add(new DateTime(2016, 01, 01));
  22. holidays.Add(new DateTime(2016, 03, 03));
  23. holidays.Add(new DateTime(2016, 05, 01));
  24. holidays.Add(new DateTime(2016, 05, 06));
  25. holidays.Add(new DateTime(2016, 05, 24));
  26. holidays.Add(new DateTime(2016, 09, 06));
  27. holidays.Add(new DateTime(2016, 09, 22));
  28. holidays.Add(new DateTime(2016, 11, 01));
  29. holidays.Add(new DateTime(2016, 12, 24));
  30. holidays.Add(new DateTime(2016, 12, 25));
  31. holidays.Add(new DateTime(2016, 12, 26));
  32.  
  33. int workingDays = 0;
  34. for (DateTime currentDate = startDate; currentDate <= endDate; currentDate =
  35. currentDate.AddDays(1))
  36. {
  37. DateTime newDate = new DateTime(2016, currentDate.Month, currentDate.Day);
  38. if (!holidays.Contains(newDate) && currentDate.DayOfWeek != DayOfWeek.Saturday && currentDate.DayOfWeek !=
  39. DayOfWeek.Sunday);
  40. {
  41. workingDays++;
  42. }
  43.  
  44.  
  45. }
  46. Console.WriteLine(workingDays);
  47. }
  48. }
  49. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement