码迷,mamicode.com
首页 > 其他好文 > 详细

ZOJ 3876 May Day Holiday

时间:2015-04-27 10:06:08      阅读:129      评论:0      收藏:0      [点我收藏+]

标签:zoj

May Day Holiday

Time Limit: 2 Seconds      Memory Limit: 65536 KB 

As a university advocating self-learning and work-rest balance, Marjar University has so many days of rest, including holidays and weekends. Each weekend, which consists of Saturday and Sunday, is a rest time in the Marjar University.

The May Day, also known as International Workers‘ Day or International Labour Day, falls on May 1st. In Marjar University, the May Day holiday is a five-day vacation from May 1st to May 5th. Due to Saturday or Sunday may be adjacent to the May Day holiday, the continuous vacation may be as long as nine days in reality. For example, the May Day in 2015 is Friday so the continuous vacation is only 5 days (May 1st to May 5th). And the May Day in 2016 is Sunday so the continuous vacation is 6 days (April 30th to May 5th). In 2017, the May Day is Monday so the vacation is 9 days (April 29th to May 7th). How excited!

Edward, the headmaster of Marjar University, is very curious how long is the continuous vacation containing May Day in different years. Can you help him?

Input

There are multiple test cases. The first line of input contains an integer T indicating the number of test cases. For each test case, there is an integer y (1928 <= y <= 9999) in one line, indicating the year of Edward‘s query.

Output

For each case, print the number of days of the continuous vacation in that year.

Sample Input

3
2015
2016
2017

Output

5
6
9
这就是很简单的日期计算,只要别忘记闰年多算一天就好了,水题。
代码如下:
#include<cstdio> 

int f[7]={6,9,6,5,5,5,5};

int main()
{
	int t;
	scanf("%d", &t);
	while(t--)
	{
		int y;
		scanf("%d", &y);
		int days=0;
		if(y==2016) printf("6\n");
		else if(y>2016)
		{
			for(int i=2017; i<=y; i++)
			{
				if((i%100==0 && i%400==0) || (i%4==0 && i%100!=0))
				{
					days+=366;
				}
				else
				{
					days+=365;
				}
			}
			int tmp=days%7;
			if(tmp==0) printf("%d\n", f[0]);
			else printf("%d\n", f[tmp]);
		}
		else
		{
			for(int i=2016; i>y; i--)
			{
				if((i%100==0 && i%400==0) || (i%4==0 && i%100!=0))
				{
					days+=366;
				}
				else
				{
					days+=365;
				}
			}
			int tmp=7-(days%7);
			if(tmp==7) printf("%d\n", f[0]);
			else printf("%d\n", f[tmp]);
		}
	}
	return 0;
}


ZOJ 3876 May Day Holiday

标签:zoj

原文地址:http://blog.csdn.net/doris1104/article/details/45290069

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!