Result: Accepted
Time: 5ms
Memory: 1092kB
#include<stdio.h>
#include<math.h>
int main()
{
int year,month,day,x,y,c,w;
while(scanf("%d %d %d",&year,&month,&day)!=EOF)
{
if(month<3)
{
month=12+month;
year=year-1;
}
y=year%100;
c=year/100;
if(year>1582)
{
w=y+(y/4)+(c/4)-2*c+(26*(month+1)/10)+day-1;
}
else if(year<1582)
{
w=y+y/4+c/4-2*c+13*(month+1)/5+day+2;
}
else if(year==1582&&month<10)
{
w=y+y/4+c/4-2*c+13*(month+1)/5+day+2;
}
else if(year==1582&&month>10)
{
w=y+(y/4)+(c/4)-2*c+(26*(month+1)/10)+day-1;
}
else if(year==1582&&month==10&&day>4)
{
w=y+(y/4)+(c/4)-2*c+(26*(month+1)/10)+day-1;
}
else if(year==1582&&month==10&&day<=4)
{
w=y+y/4+c/4-2*c+13*(month+1)/5+day+2;
}
x=(w%7+7)%7;
if(x==1)
{
printf("Monday\n");
}
if(x==2)
{
printf("Tuesday\n");
}
if(x==3)
{
printf("Wednesday\n");
}
if(x==4)
{
printf("Thursday\n");
}
if(x==5)
{
printf("Friday\n");
}
if(x==6)
{
printf("Saturday\n");
}
if(x==0)
{
printf("Sunday\n");
}
}
}