当前位置: 代码迷 >> 综合 >> NYOJ - An problem about date
  详细解决方案

NYOJ - An problem about date

热度:9   发布时间:2024-01-20 18:05:14.0

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 main()
{int year,month,day;while(scanf("%d%d%d",&year,&month,&day) != EOF){if(month == 1||month == 2)     //吉姆拉尔森公式要注意,当月份为1或2的时候,变成13或14,年份数值减少1{month += 12;year--;}int k =((day+2*month+3*(month+1)/5+year+year/4-year/100+year/400) + 1) % 7;printf("%d\n",k);}return 0;
}

这题很水的,主要是用到了吉姆拉尔森公式,但是,公式的使用有前提条件注意一下就行了,还有结果要加1,再取余!这题已经AC,这里提供参考。

  相关解决方案