华为机试:星期几的问题

1990年1月1日 是星期一,
输入:1990 1 1  输出 monday

输入:2013 9 17 输出 tuesday

#include<stdio.h>
void main()
{
	int year,mouth,day,week,lemp;
	int sum=0;
	scanf("%d%d%d",&year,&mouth,&day);
	for(int i=1990;i<year;i++){
		if((i%4==0&&i%100!=0)||i%400==0){
			sum+=366;
		}else{
			sum+=365;
		}
	}
	if((year%4==0&&year%100!=0)||year%400==0){
		lemp=1;
	}else{
		lemp=0;
	}
	switch(mouth-1)
	{
	case 11:sum+=30;
	case 10:sum+=31;
	case 9:sum+=30;
	case 8:sum+=31;
	case 7:sum+=31;
	case 6:sum+=30;
	case 5:sum+=31;
	case 4:sum+=30;
	case 3:sum+=31;
	case 2:sum+=28+lemp;
	case 1:sum+=31;
	}	
	sum+=day;
	week=sum%7;
	if(week!=0){
		printf("%d年%d月%d日是星期%d",year,mouth,day,week);
	}else{
		printf("%d年%d月%d日是星期日",year,mouth,day);
	}

}


你可能感兴趣的:(华为机试:星期几的问题)