USACO-Section1.1 Friday the Thirteenth

来源:互联网 发布:js fetch api 编辑:程序博客网 时间:2024/06/05 19:39

Friday the Thirteenth

本题主要内容是根据所给日期,计算星期几,再简化,就是计算两个日期间的间隔,这时用儒略日计算就比较方便。儒略日的计算方法可另行查找。
代码如下:

/*ID: xhzdcyy1PROB: fridayLANG: C++         */#include <iostream>#include <fstream>#include <string>using namespace std;int main(){    ofstream fout ("friday.out");    ifstream fin ("friday.in");    int n;    fin>>n;    int arr[7]={0};    int jd;    int y,m,day,a,year,month;    year=1900;    month=1;    day=13;    while(year<1900+n){        a=(14-month)/12;        y=year+4800-a;        m=month+12*a-3;        jd=(153*m+2)/5+365*y+y/4-y/100+y/400+day-32045;        ++arr[(jd+2)%7];        if(month==12){            month=1;            ++year;        }        else{            ++month;        }    }    for(int i=0;i<7;i++){        fout<<arr[i];        if(i!=6) fout<<" ";    }    fout<<endl;    return 0; }
原创粉丝点击