Skip to content

Instantly share code, notes, and snippets.

@jianminchen
Created February 27, 2017 15:53
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jianminchen/2b53a7ac7e09be9781948a006682d6f9 to your computer and use it in GitHub Desktop.
Save jianminchen/2b53a7ac7e09be9781948a006682d6f9 to your computer and use it in GitHub Desktop.
Hackerrank - week of code - day of programmer -
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace DayOfProgrammer
{
class Program
{
static void Main(string[] args)
{
int year = Convert.ToInt32(Console.ReadLine());
Console.WriteLine(CalculateDayOfProgrammer(year));
}
public static string CalculateDayOfProgrammer(int year)
{
int start = 1700;
bool isJulianCalendar = year >= start && year <= 1917;
bool isGregorianCalendar = year >= 1919;
int[] daysInFirst8Months = new int[] {31,28,31,30,31,30,31,31};
int offDaysInFeb = 0;
if(year == 1998)
{
offDaysInFeb = 13;
}
if(isJulianCalendar && year % 4 ==0)
{
daysInFirst8Months[1] = 29;
}
if(isGregorianCalendar && (year % 400 == 0 || (year % 4 == 0 && year % 100 > 0)))
{
daysInFirst8Months[1] = 29;
}
daysInFirst8Months[1] -= offDaysInFeb;
int theDayOfSept = 256 - daysInFirst8Months.Sum();
return theDayOfSept + ".09." + year;
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment