Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- public class Program
- {
- public static void Main()
- {
- int targetYear = -34567;
- int year = 2011;
- int month = 1;
- int date = 1;
- int day = 6;
- string f13s = "";
- /*
- Day:
- 0 = Sunnudagur
- 1 = Mánudagur
- 2 = Þriðjudagur
- 3 = Miðvikudagur
- 4 = Fimmtudagur
- 5 = Föstudagur
- 6 = Laugardagur
- */
- while (year >= targetYear)
- {
- date--;
- day--;
- if (day == -1) day = 6;
- if (date == 0)
- {
- month--;
- if (month == 0)
- {
- month = 12;
- year--;
- }
- date = DaysInMonth(year, month);
- }
- if (year == targetYear && date == 13 && day == 5) f13s = month.ToString() + f13s;
- }
- Console.WriteLine(f13s);
- }
- public static int DaysInMonth(int year, int month)
- {
- switch (month)
- {
- case 1:
- case 3:
- case 5:
- case 7:
- case 8:
- case 10:
- case 12: return 31;
- case 2: return IsLeapYear(year) ? 29 : 28;
- default: return 30;
- }
- }
- public static bool IsLeapYear(int year)
- {
- if (year % 400 == 0) return true;
- else if (year % 100 == 0) return false;
- else if (year % 4 == 0) return true;
- else return false;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement