/********************************* * 日期:2013-1-11 * 作者:SJF0115 * 题号: 九度1043 * 题目:Day of Week * 来源:http://ac.jobdu.com/problem.php?pid=1043 * 结果:AC * 题意: * 总结: **********************************/ #include <stdio.h> #include <string.h> int dayOfMonth[13][2] = { 0,0, 31,31, 28,29, 31,31, 30,30, 31,31, 30,30, 31,31, 31,31, 30,30, 31,31, 30,30, 31,31, }; char monthName[13][20] = { " ", "January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December" }; char weekName[8][20] = { " ", "Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday" }; //判断闰年 int leap_year(int year){ if((year%100 != 0 && year%4 == 0) || (year % 400 == 0)){ return 1; } else{ return 0; } } //计算天数 int TDay(int day,char month[],int year){ int day1 = 0,i,j; int isleap_year = leap_year(year); for(i = 1;i< year;i++){ if(leap_year(i)){ day1 += 366; } else{ day1 += 365; } } for(i = 1;i < 13;i++){ if(strcmp(month,monthName[i]) == 0){ break; } } for(j = 1;j < i;j++){ day1 += dayOfMonth[j][isleap_year]; } day1 += day; return day1%7+1; } int main() { int day,year; char month[20]; //freopen("C:\\Users\\SJF\\Desktop\\acm.txt","r",stdin); while(scanf("%d%s%d",&day,month,&year) != EOF) { printf("%s\n",weekName[TDay(day,month,year)]); } return 0; }