Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
- namespace laborab3
- {
- class Program
- {
- enum MonthName
- {
- January,
- February,
- March,
- April,
- May,
- June,
- July,
- August,
- September,
- October,
- November,
- December
- }
- static List<int> DaysInMonths = new List<int>() { 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 };
- static List<int> DaysInMonths1 = new List<int>() { 31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 };
- static void Main(string[] args)
- {
- try
- {
- Console.Write("Please enter the year: ");
- int yearNum = Convert.ToInt32(Console.ReadLine());
- bool isLeapYear = (yearNum % 4 == 0 && yearNum % 100 != 0 || yearNum % 400 == 0);
- int maxDayNum = isLeapYear ? 366 : 365;
- Console.Write("Please enter a day number between 1 and 365: ");
- string line = Console.ReadLine();
- int dayNum = int.Parse(line);
- if (dayNum < 1 || dayNum > 365)
- {
- throw new ArgumentOutOfRangeException("Day out of range");
- }
- int monthNum = 0;
- if (isLeapYear)
- {
- foreach (int daysInMonth in DaysInMonths1)
- {
- if (dayNum <= daysInMonth)
- {
- break;
- }
- else
- {
- dayNum -= daysInMonth; monthNum++;
- }
- }
- }
- else
- {
- foreach (int daysInMonth in DaysInMonths)
- {
- if (dayNum <= daysInMonth)
- {
- break;
- }
- else
- {
- dayNum -= daysInMonth; monthNum++;
- }
- }
- }
- MonthName temp = (MonthName)monthNum;
- string monthName = temp.ToString();
- Console.WriteLine("{0} {1}", dayNum, monthName);
- Console.ReadKey();
- }
- catch (Exception e)
- {
- Console.WriteLine($"Ошибка: {e.Message}");
- }
- Console.ReadKey();
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement