An problem about date(数学 )
2015-04-23 16:37
190 查看
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
code:
公式:k=(Day +1+ 2*Month + 3*(Month+1)/5 + Year + Year/4 - Year/100 + Year/400) % 7;
需要注意的地方就是1月和2月算作上年的13月,和14月。
#include<stdio.h> int main() { int year,mouth,day,k,ans; while(scanf("%d %d %d",&year,&mouth,&day)!=EOF) { if(mouth==1) { mouth=13;year-=1; } if(mouth==2) { mouth=14;year-=1; } k=1+day+2*mouth+3*(mouth+1)/5+year/400-year/100+year+year/4; ans=k%7; printf("%d\n",ans); } return 0; }数学是神造的科学!
相关文章推荐
- NYOJ219 An problem about date 【数学】
- NYOJ 题目219 An problem about date(数学,吉姆拉尔森公式)
- NYOJ 219-An problem about date
- NYOJ 219 An problem about date
- NYOJ—An problem about date【水题|公式题】
- nyoj-An problem about date
- NYOJ-An problem about date(基姆拉尔森公式)
- 219 An problem about date【日期的定理】
- NYOJ - An problem about date
- An problem about date 根据年月日计算 星期几
- NYOJ--An problem about date
- 南阳oj-An problem about date
- NYOJ 219 An problem about date
- An problem about date(nyoj 219)
- NYOJ题目219-An problem about date
- NYOJ 219 An problem about date
- NYOJ 题目219 An problem about date
- (NYoj 219)An problem about date ——日期万能公式(基姆拉尔森计算公式)
- nyoj-219-An problem about date
- NYOJ An problem about date