Friday the Thirteenth 黑色星期五

Description

13号又是一个星期5。13号在星期五比在其他日子少吗?为了回答这个问题,写一个程序,要求计算每个月的十三号落在周一到周日的次数。给出N年的一个周期,要求计算1900年1月1日至1900+N-1年12月31日中十三号落在周一到周日的次数,N为正整数且不大于400. 这里有一些你要知道的: 1900年1月1日是星期一.4,6,11和9月有30天.其他月份除了2月都有31天.闰年2月有29天,平年2月有28天.年份可以被 4整除的为闰年(1992=4*498 所以 1992年是闰年,但是1990年不是闰年)以上规则不适合于世纪年.可以被400整除的世纪年为闰年,否则为平年.所以,1700,1800,1900 和2100年是平年,而2000年是闰年.请不要预先算好数据(就是叫不准打表 0。0)!

Input

一个正整数n.

Output

七个在一行且相分开的整数,它们代表13日是星期六,星期日,星期一...星期五的次数.

Sample Input

20

Sample Output

36 33 34 33 35 35 34 
    #include <algorithm>
    #include <iostream>
    #include <cstdio>
    #include <cstring>
    #include <cmath>
    using namespace std;
    typedef long long ll;
    int main()
    {
        ll a[7]={0},i,n,aa=1,j,k;
        ll b[12]={31,28,31,30,31,30,31,31,30,31,30,31};
        scanf("%lld",&n);
        for(i=1900;i<=1900+n-1;i++)
        {
            if(i%400==0||i%4==0&&i%100!=0)
                b[1]=29;
            else
                b[1]=28;
            for(j=0;j<12;j++)
            {
                ll m=(aa+13)%7;
                a[m]++;
                aa+=b[j];
                aa%=7;
            }
        }
        printf("%lld",a[0]);
        for(i=1;i<7;i++)
            printf(" %lld",a[i]);
        return 0;
    }

 

posted @ 2018-09-03 19:54  ~~zcy  阅读(157)  评论(0编辑  收藏  举报