标签:
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?
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.
For each case, print the number of days of the continuous vacation in that year.
3 2015 2016 2017
5 6 9
集体团结把这题ac了。。
#include<iostream> #include<stdio.h> #include<string.h> #include<string> #include<math.h> #include<algorithm> using namespace std; int rn(int year) { if(year%400==0 ||(year%4==0&&year%100!=0)) return 1; else return 0; } struct Yea { bool run; int xq; }; Yea Y[10000]; int main() { int i; for(i=1928;i<=9999;i++) { if(rn(i)) Y[i].run=1; else Y[i].run=0; } Y[2015].xq=5; for(i=2014;i>=1928;i--) { if(Y[i].run==0 &&Y[i+1].run ) Y[i].xq=(Y[i+1].xq-2+7)%7; else Y[i].xq=(Y[i+1].xq-1+7)%7; } for(i=2016;i<=9999;i++) { if(Y[i].run) Y[i].xq=(Y[i-1].xq+2)%7; else Y[i].xq=(Y[i-1].xq+1)%7; } int T,year; while(cin>>T) { while(T--) { cin>>year; if(Y[year].xq==1) cout<<"9"<<endl; else if(Y[year].xq==2) cout<<"6"<<endl; else if(Y[year].xq==0 ||Y[year].xq==7) cout<<"6"<<endl; else cout<<"5"<<endl; } } return 0; }
标签:
原文地址:http://blog.csdn.net/zuguodexiaoguoabc/article/details/45273919