Advertisement
Guest User

Untitled

a guest
Feb 20th, 2020
75
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.72 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Threading.Tasks;
  6.  
  7. namespace laborab3
  8. {
  9. class Program
  10. {
  11. enum MonthName
  12. {
  13. January,
  14. February,
  15. March,
  16. April,
  17. May,
  18. June,
  19. July,
  20. August,
  21. September,
  22. October,
  23. November,
  24. December
  25. }
  26. static List<int> DaysInMonths = new List<int>() { 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 };
  27. static List<int> DaysInMonths1 = new List<int>() { 31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 };
  28. static void Main(string[] args)
  29. {
  30. try
  31. {
  32. Console.Write("Please enter the year: ");
  33. int yearNum = Convert.ToInt32(Console.ReadLine());
  34. bool isLeapYear = (yearNum % 4 == 0 && yearNum % 100 != 0 || yearNum % 400 == 0);
  35.  
  36.  
  37. int maxDayNum = isLeapYear ? 366 : 365;
  38. Console.Write("Please enter a day number between 1 and 365: ");
  39. string line = Console.ReadLine();
  40. int dayNum = int.Parse(line);
  41. if (dayNum < 1 || dayNum > 365)
  42. {
  43. throw new ArgumentOutOfRangeException("Day out of range");
  44. }
  45. int monthNum = 0;
  46. if (isLeapYear)
  47. {
  48. foreach (int daysInMonth in DaysInMonths1)
  49. {
  50. if (dayNum <= daysInMonth)
  51. {
  52. break;
  53. }
  54. else
  55. {
  56. dayNum -= daysInMonth; monthNum++;
  57. }
  58. }
  59.  
  60. }
  61. else
  62. {
  63.  
  64. foreach (int daysInMonth in DaysInMonths)
  65. {
  66. if (dayNum <= daysInMonth)
  67. {
  68. break;
  69. }
  70. else
  71. {
  72. dayNum -= daysInMonth; monthNum++;
  73. }
  74. }
  75. }
  76. MonthName temp = (MonthName)monthNum;
  77. string monthName = temp.ToString();
  78.  
  79. Console.WriteLine("{0} {1}", dayNum, monthName);
  80. Console.ReadKey();
  81. }
  82. catch (Exception e)
  83. {
  84. Console.WriteLine($"Ошибка: {e.Message}");
  85. }
  86. Console.ReadKey();
  87.  
  88. }
  89. }
  90. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement