NYOJ题目219-An problem about date
2017-08-23 21:47
232 查看
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
4000
样例输出
0 6 5 3
说实话看到这个题目的时候真的很蒙,因为我完全不知道怎么求具体星期几,然后就发现了这个公式
公式:k=(Day +1+ 2*Month + 3*(Month+1)/5 + Year + Year/4 - Year/100 + Year/400) % 7;
需要注意的地方就是1月和2月算作上年的13月,和14月。
#include <cstdio> #include <iostream> using namespace std; int main() { int year,mouth,day,k,ans; while(scanf("%d %d %d",&year,&mouth,&day)!=EOF) { if(mouth==1||mouth==2) { mouth += 12; year--; } 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; }
相关文章推荐
- 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 219 An problem about date 日期计算 附加最优代码(基姆拉尔森公式)
- nyoj 219 An problem about date
- NYOJ219 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
- An problem about date(nyoj 219)
- NYOJ 219 An problem about date
- NYOJ219-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(吉姆拉尔森公式)