USACO 1.0_Friday the Thirteenth

還好還好蛋沒有粉

/*
NAME: zfb2
LANG: C++
TASK: friday
*/

#include <iostream>
#include <fstream>
#include <math.h>
using namespace std;

int sun=0, mon=0, tue=0, wed=0, thu=0, fri=0, sat=0;
   
bool 
leap(int n)
{
    if((n%4==0&&n%100!=0)||n%400==0)
        return true;
    else
        return false;
}

void
fun(int tol) 
{   
    switch(tol%7){
        case 0: sun++; break;
        case 1: mon++; break;
        case 2: tue++; break;
        case 3: wed++; break;
        case 4: thu++; break;
        case 5: fri++; break;
        case 6: sat++; break;
    }
}


int 
main()
{
    freopen("friday.in", "r", stdin);
    freopen("friday.out", "w", stdout);
    int N;
    cin>>N;
    int sum=0;
    for(int i=1900; i<=1900+N-1; i++){
        for(int j=1; j<=12; j++){
            switch(j){
                case 1:case 3:case 5:case 7:case 8:case 10:case 12: 
                     {fun(sum+13); sum+=31;} break;
                case 4:case 6:case 9:case 11: 
                     {fun(sum+13); sum+=30;} break;
                case 2:
                     {
                     if(leap(i))
                         {fun(sum+13); sum+=29;}
                     else
                         {fun(sum+13); sum+=28;}    
                     }
                     break;
            }
        }
    }
    
    cout<<sat<<" "<<sun<<" "<<mon<<" "<<tue<<" "<<wed<<" "<<thu<<" "<<fri<<endl;
    /*int i=1900;
    /*while(i<=1920)
    {cout<<i<<"    "<<leap(i)<<endl;i++;}*/
    //cin>>N;
    return 0;
}

你可能感兴趣的:(USACO 1.0_Friday the Thirteenth)