题目大意:
17th Nov,2007.是星期6,问某年某月某日是星期几
year(0<year<10000), month(0<=month<13), day(0<=day<32).
if the date is illegal, you should output "illegal". Or, you should output what day it is.
/*蔡勒公式
1582/10/4之后时
W=[C/4]-2C+y+[y/4]+[13*(M+1)/5]+d-1
1582/10/4之前时
w=y+[y/4]+[c/4]-2c+[13(m+1)/5]+d+2
w:星期; w对7取模得:0-星期日,1-星期一,2-星期二,3-星期三,4-星期四,5-星期五,6-星期六
c:世纪减1(年份前两位数)
y:年(后两位数)
m:月(m大于等于3,小于等于14,即在蔡勒公式中,某年的1、2月要看作上一年的13、14月来计算,
比如2003年1月1日要看作2002年的13月1日来计算)
d:日
*/
#include<iostream>
#include<cstdio>
using namespace std;
char s[7][10]= {"Sunday","Monday","Tuesday","Wednesday","Thursday","Friday","Saturday"};
int m1[13]= {0,31,28,31,30,31,30,31,31,30,31,30,31};
int m2[13]= {0,31,29,31,30,31,30,31,31,30,31,30,31};
bool run(int a)
{
if(a%100!=0&&a%4==0||a%400==0)
return 1;
return 0;
}
int main()
{
int year,month,day;
while(~scanf("%d%d%d",&year,&month,&day))
{
if(year<=0||month<=0||month>=13||day<=0||day>=32)
puts("illegal");
else if(run(year)&&day>m2[month]||!run(year)&&day>m1[month])
puts("illegal");
else
{
if(month<3)
year-=1,month+=12;
int c=year/100,y=year%100;
int w=c/4-2*c+y+y/4+13*(month+1)/5+day-1;
printf("%s\n",s[(w%7+7)%7]);//w可能为负
}
}
return 0;
}