【C】星期判断

#include 
#include 

char Week[7][20] = {"Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday"};
char Month[13][20] = {"", "1", "2", "3", "4", "5", "6", "7", "8", "9", "10", "11", "12"};
int DaysOfMonth[13] = {0, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};

//判断闰年
int leap(int y){
	return (y%4==0 && y%100!=0 || y%400==0);
}

main(){
	int date, year, nmonth, i, days;
	char cmonth[20];
	while(~scanf("%d %s %d", &year, cmonth, &date)){
		for(i=1; i<=12; i++){
			if(strcmp(cmonth, Month[i])==0){
				nmonth = i;
				break;
			}
		}
		//计算总天数
		days = (year - 1) * 365;
		for(i=1; i2 && leap(year))			//该年闰月
			days += 1;

		//输出星期
		puts(Week[days%7]);
	}
}

你可能感兴趣的:(C,C)