Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class Solution
- {
- public static void Main()
- {
- int[] bdayDateArr = Console.ReadLine().Split(' ', 2).Select(Int32.Parse).ToArray();
- int[] nowDateArr = Console.ReadLine().Split(' ', 3).Select(Int32.Parse).ToArray();
- int nowDate = nowDateArr[0];
- int nowMonth = nowDateArr[1];
- int nowYear = nowDateArr[2];
- int bdayDate = bdayDateArr[0];
- int bdayMonth = bdayDateArr[1];
- int bdayYear = nowYear;
- if (bdayDate == 29
- && bdayMonth == 2)
- {
- // calc next leap year
- while (!(bdayYear % 4 == 0 || bdayYear % 100 != 0 && bdayYear % 4 == 0))
- {
- bdayYear++;
- }
- }
- // Constraints
- if (nowYear is < 1920 or > 3000
- || nowMonth is < 1 or > 12
- || nowDate < 1 || nowDate > DateTime.DaysInMonth(nowYear, nowMonth)
- || bdayMonth is < 1 or > 12
- || bdayDate < 1 || bdayDate > DateTime.DaysInMonth(bdayYear, bdayMonth))
- {
- return;
- }
- DateTime now = new(nowYear, nowMonth, nowDate);
- DateTime birthday = new(bdayYear, bdayMonth, bdayDate);
- if (now > birthday)
- {
- birthday = birthday.AddYears(1);
- }
- int daysUntilBirthday = (birthday - now).Days;
- Console.WriteLine(daysUntilBirthday);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement