USACO Friday the Thirteenth

题目过于简单

用一个变量cday去表示当前日子,cday为0代表星期天

/*
ID: kdk5501
TASK : friday
LANG : C++
*/

#include <iostream>
#include <fstream>
#include <string>

using namespace std;
struct people
{
    string name;
    int money;
}person[110];


int main() 
{    

    int day[13]={0,31,28,31,30,31,30,31,31,30,31,30,31};
    int ans[8]={0,0,0,0,0,0,0,0};
    freopen("friday.in","r",stdin);
    freopen("friday.out","w",stdout);
    int n;
    cin>>n;
    bool st=false;
    int cday=1;
    for(int i=1900;i<=1900+n-1;i++)
    {
        st=false;
        if((i%4==0&&i%100!=0)||i%400==0)
        {
            st=true;
            day[2]++;
        }
        for(int j=1;j<=12;j++)
        {    
            ans[(cday+12)%7]++;
            cday=(cday+day[j])%7;
        }

        if(st==true)
        {
            day[2]--;
        }
    }

    cout<<ans[6]<<" "<<ans[0]<<" ";
    for(int i=1;i<=5;i++)
    {
        cout<<ans[i];
        if(i!=5)    cout<<" ";
    }
    cout<<endl;
    return 0;
}

 

上一篇:自适应自旋锁--吞吐量和延迟以及管理开销的折中


下一篇:07 - 面向对象编程(高级部分二)