Created
January 7, 2015 13:43
-
-
Save kenornotes/7ec44daef6e56e6201ff to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #include <stdio.h> | |
| //return if input is leap year | |
| int leap(int year) { | |
| return year % 400 == 0 || (year % 4 == 0 && year % 100 != 0); | |
| } | |
| //return leap day between base day and target day. | |
| int leapDay(int year, int month, int date) { | |
| int count = 0, i; | |
| //大於等於基準日 2000 / 01 / 01 | |
| if(year >= 2000) { | |
| for(i = 2000; i <= year; i++) { | |
| if(leap(i)) count ++; | |
| } | |
| if(leap(year) && month < 3) | |
| count --; | |
| //小於基準日 2000 / 01 /01 | |
| } else { | |
| for(i = year; i < 2000; i++) { | |
| if(leap(i)) count ++; | |
| } | |
| if(leap(year) && (month > 3)) | |
| count --; | |
| count *= -1; // 小於基準日,閏日改為負數 | |
| } | |
| return count; | |
| } | |
| int main() { | |
| int year, month, date, day; | |
| //store month code | |
| int monthCode[12] = {5, 1, 1, 4, 6, 2, 4, 0, 3, 5, 1, 3}; | |
| scanf("%d %d %d", &year, &month, &date); | |
| day = (year - 2000 + leapDay(year, month, date) + monthCode[month-1] + date) % 7; | |
| printf("%d\n", day >= 0 ? day : day + 7); | |
| return 0; | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment