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

May Day Holiday

时间:2015-04-26 12:31:14      阅读:201      评论:0      收藏:0      [点我收藏+]

标签:浙江省赛

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

题意:2015年浙江省省赛。

输入一个年份,求这一年中五一放几天假(假期最少要为五天)

思路:打表

先求出5月1号是星期几

星期一:放9天

星期二:放6天

星期三:放5天

星期四:放5天

星期五:放5天

星期六:放5天

星期天:放6天

再输出。

如果上一年是平年,这一年是瑞年,5月1号就是在上一年的基础上+2

其他的就是在上一年的基础上+1

#include<iostream>
#include<cstdio>
using namespace std;
int a[10000],b[8]={0,9,6,5,5,5,5,6};
int fun1(int n)
{
   if(n%400==0||(n%4==0&&n%100!=0)) return 1;
   return 0; 
}
int fun()
{
  int i,j,r;
  a[1928]=2;
  for(i=1929;i<10000;i++)
   {
     if(!fun1(i-1)&&fun1(i)) 
         {
            r=a[i-1]+2;
            if(r>7) a[i]=r%7;
              else a[i]=r;
         }
     else 
        {
           r=a[i-1]+1;
             if(r>7) a[i]=r%7;
               else a[i]=r;
        }
   }
      
}
int main()
{
int t,n,i,j;
 fun();
while(scanf("%d",&t)!=EOF)
{
   while(t--)
   {
     scanf("%d",&n);
     printf("%d\n",b[a[n]]);        
   }                       
}   
return 0;
}

May Day Holiday

标签:浙江省赛

原文地址:http://blog.csdn.net/u012346225/article/details/45286555

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