题目描述
13 号又是一个星期五,那么 13号在星期五比在其他日子少吗?
为了回答这个问题,写一个程序,要求计算每个月的十三号落在周一到周日的次数。给出 n 年的一个周期,要求计算 1900 年 11 月 11 日至 1900+n−1 年 12 月 31 日中十三号落在周一到周日的次数。
这里有一些你要知道的:
1、1900 年 11 月 11 日是星期一。
2、4,6,11 和 9 月有 30 天,其他月份除了 2 月都有 31天,闰年 2月有 29 天,平年 2 月有 28天。
3、年份可以被 4 整除的为闰年 ( 1992=4∗498 所以 1992 年是闰年,但是 1990 年不是闰年 )。
4、以上规则不适合于世纪年。可以被 400 整除的世纪年为闰年,否则为平年。所以,1700,1800,1900,2100 年是平年,而 2000 年是闰年。
输入输出格式
输入格式
一个正整数 n。
输出格式
依次输出周六、日、一、二、三、四、五在 13日出现的次数。
输入输出样例
輸入資料 1
20
Copy
輸出資料 1
輸出資料 1
36 33 34 33 35 35 34
Copy
首先,我们来观察题目,其实本题就是一道闰年个数加强版*n倍,只要能弄懂如何求出闰年个数,本题就迎刃而解。
#include <bits/stdc++.h>
#include<iostream>
#include<algorithm>
#include<cstdlib>
#include<cstring>
#include<cstdio>
#include<string>
#include<vector>
#include<bitset>
#include<queue>
#include<deque>
#include<stack>
#include<cmath>
#include<list>
#include<map>
#include<set> //令人“愉悦”的头文件
#define RI register int
using namespace std;
typedef long long ll;
const int N=100000+10;
const int MOD=1e9+7;
const double PI = acos(-1.0);
const double EXP = 1E-8;
const int INF = 0x3f3f3f3f;
int n,m,k,q,ans;
struct date {int yy,mm,ww;};
bool operator<(const date &a,const date &b) {
if(a.yy!=b.yy) return a.yy<b.yy;
if(a.mm!=b.mm) return a.mm<b.mm;
return 0;
}
int d[2][13]= {31,28,31,30,31,30,31,31,30,31,30,31,0,31,29,31,30,31,30,31,31,30,31,30,31,0};
void operator++(date &a) {
bool spl=0;
if(a.yy%400==0||(a.yy%4==0&&a.yy%100!=0)) spl=1;
a.ww+=d[spl][a.mm++],a.ww%=7;
if(a.mm==12) a.yy++,a.mm=0;
}
char str;
int main()
{
#ifdef DEBUG
freopen("input.in", "r", stdin);
#endif
int t[7]={0};
scanf("%d",&n);
date a=(date) {1900,0,5};
date b=(date) {1900+n-1,11,-1};
while(!(b<a)) t[a.ww]++,++a;
for(int i=5; i<12; i++) printf("%d ",t[i%7]);
return 0;
}