`
YuHuang.Neil
  • 浏览: 180723 次
  • 性别: Icon_minigender_1
  • 来自: 北京
社区版块
存档分类
最新评论
阅读更多
问题:
We now use the Gregorian style of dating in Russia. The leap years are years with number divisible by 4 but not divisible by 100, or divisible by 400.
For example, years 2004, 2180 and 2400 are leap. Years 2004, 2181 and 2300 are not leap.
Your task is to write a program which will compute the day of week corresponding to a given date in the nearest past or in the future using today’s agreement about dating.

输入:
There is one single line contains the day number d, month name M and year number y(1000≤y≤3000). The month name is the corresponding English name starting from the capital letter.

输出:
Output a single line with the English name of the day of week corresponding to the date, starting from the capital letter. All other letters must be in lower case.

实现代码:

#include <stdio.h>
#include <string.h>

char *week[]={"Monday","Tuesday","Wednesday",
"Thursday","Friday","Saturday","Sunday"};

char *month[]={"January","February","March","April",
"May","June","July","August","September","October",
"November","December"};

int main(){
	int y,m,d,i,a;
	char mon[15];
	for(;~scanf("%d %s %d",&d,mon,&y);){
		for(i=0;i<12;++i) if(!strcmp(mon,month[i])) break;
		m=i+1;
		if(m==1||m==2) {
			m+=12;y--;
		}
		if((y<1752)||(y==1752&&m<9)||
			(y==1752&&m==9&&d<3))
			a=(d+2*m+3*(m+1)/5+y+y/4+5)%7;
		else
			a=(d+2*m+3*(m+1)/5+y+y/4-y/100+y/400)%7;
		printf("%s\n",week[a]);
	}
	return 0;
}



运行结果:



  • 大小: 21.8 KB
分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics