USACO 1.2 Friday the Thirteenth

注意闰月的部分细节很多。

/*
ID:Starry21
LANG:C++
TASK:friday                 
*/
#include<iostream>
#include<string>
#include<cstdio>
#include<cstring>
#include<map>
using namespace std;
#define N 405
int n;
int ans[10];
int main() 
{
    //freopen("friday.in","r",stdin);
    //freopen("friday.out","w",stdout);
    scanf("%d",&n);
    int lw=1,m,d=0,r;
    for(int i=1;i<=n;i++)
    {
        int y=1900+i-1;
        if(y%100==0)
        {
            if(y%400==0) r=1;
            else r=0;
        }
        else if(y%4==0) r=1;
        else r=0;
        //printf("%d %d\n",y,r);
        for(m=1;m<=12;m++)
        {
            d=d+13;
            int res=(d+lw-1)%7;
            if(res==0) res=7;
            lw=res;
            lw++;lw=lw%7;
            if(lw==0) lw=7;
            ans[res]++;
            if(m==4||m==6||m==11||m==9) d=30-13;
            else if(m==1||m==3||m==5||m==7||m==8||m==10||m==12) d=31-13;
            else if(m==2)
            {
                if(r) d=29-13;
                else d=28-13;
            }
        }
    }
    printf("%d %d ",ans[6],ans[7]);
    for(int i=1;i<5;i++)
        printf("%d ",ans[i]);
    printf("%d\n",ans[5]);
    return 0;
}

猜你喜欢

转载自www.cnblogs.com/lyttt/p/11918571.html