NYOJ-219-An problem about date(蔡勒公式根据日期推周几)

来源:互联网 发布:营销qq for mac 编辑:程序博客网 时间:2024/06/04 19:52

An problem about date
时间限制:2000 ms | 内存限制:65535 KB
难度:2
描述
acm的iphxer经常忘记某天是星期几,但是他记那天的具体日期,他希望你能写个程序帮帮他。

输入
每行有三个整数 year,month,day,日期在1600年1月1日到9600年1月1日之间;
输出
输出对应的星期,用一个整数表示;(星期一到星期六用1-6表示,星期日用0表示)
样例输入
2011 3 6
1949 10 1
2011 4 1
1945 8 15
样例输出
0
6
5
3

涨姿势了,原来还有这种公式
蔡勒公式戳这里

坑点:请去掉所有多余的头文件并使用标准输入输出,数据量特别大,一言不合就超时

代码

#include<stdio.h>//蔡勒公式int Change(int year,int month,int day)//根据日期判断出星期几{    if(month==1||month==2)    {        month+=12;        year--;    }    int c=year/100;    int y=year%100;    int m=month;    int d=day;    int W=c/4-2*c+y+y/4+26*(m+1)/10+d-1;    if(W<0)        return (W+(-W/7+1)*7)%7;    return W%7;}int main(){    int year,month,day;    while(~scanf("%d%d%d",&year,&month,&day))    {        printf("%d\n",Change(year,month,day));    }    return 0;}
0 0
原创粉丝点击