Title Description
Known November 11, 2011 is Friday, ask yyyy mm month DD Day is the days of the week? Note Consider the case of a leap year. In particular, every hundred years do not leap, the 400-year leap in the situation.
Enter a description
Enter only one row
YYYY MM DD
Output description
Output has only one row
W
Input sample
1599 1 1
Output sample
5
Analysis
Kimlarsson Calculation formula:
W= (d+2*m+3* (m+1)/5+y+y/4-y/100+y/400+1)%7
(need to use Switch...case statement to determine the day of the week)
Improved:
W= (d+2*m+3* (m+1)/5+y+y/4-y/100+y/400)%7+1
(Calculated results are directly corresponding to the day of the week)
Attention:
When month=1 or 2 o'clock, it needs to be changed to month+12 and year-1
Test code
1#include <stdio.h>2 3 intMainvoid)4 {5 intYear , month, day;6 intx;7 8scanf"%d%d%d", &year, &month, &Day );9 if(Month = =1|| month = =2)Ten { OneMonth + = A; Ayear--; - } -x = (Day +2* Month +3* (Month +1) /5+ year + year/4-year/ -+ year/ -) %7+1; theprintf"%d\n", x); - return 0; -}
Algorithm to improve date calculation