题目地址:http://ac.jobdu.com/problem.php?cid=1040&pid=6
C语言源码:
#include<stdio.h>
#include<string.h>
int leap(int year)
{
if((year%4==0&&year%100!=0)||year%400==0)
return 1;
else
return 0;
}//判断是不是闰年
int daynum(int year,int month,int day)
{
int i,sum;
i=1;
sum=0;
while(i<month)
{
if(i==1||i==3||i==5||i==7||i==8||i==10||i==12)
sum+=31;
else
if(i!=2)
sum+=30;
else
if(leap(year))
sum+=29;
else
sum+=28;
i++;
}
return sum+day;
}//计算距离当年1月1号的天数
int main()
{
char mon[12][10]={"January","February","March","April","May","June","July","August","September","October","November","December"};
char we[7][10]={"Sunday","Monday","Tuesday","Wednesday","Thursday","Friday","Saturday"};
int i,day,year,month,week,sum;
char m[10];
while(scanf("%d %s %d",&day,m,&year)!=EOF)
{
for(i=0;i<12;i++)
{
if(strcmp(m,mon[i])==0)
month=i+1;
}
sum=0;
if(year==2013)
sum=daynum(year,month,day)-daynum(2013,1,17);
else
if(year>2013)
{
i=2014;
while(i<year)
{
if(leap(i))
sum+=366;
else
sum+=365;
i++;
}
sum+=365-daynum(2013,1,17)+daynum(year,month,day);
}
else
{
i=year+1;
while(i<2013)
{
if(leap(i))
sum+=366;
else
sum+=365;
i++;
}
sum+=365+daynum(2013,1,17)-daynum(year,month,day);
if(leap(year))
sum+=1;
sum=-sum;
}//计算输入年份与2013年1月17号的差距天数,有正负
week=((4+sum)%7+7)%7;
printf("%s\n",we[week]);
}
}