NYOJ-An problem about date(基姆拉尔森公式)
2017-03-21 15:55
393 查看
问题链接:http://acm.nyist.net/JudgeOnline/problem.php?pid=219
题目描述:给你年月日,计算当天星期几
基姆拉尔森公式:W= (d+2*m+3*(m+1)/5+y+y/4-y/100+y/400+1)%7
在公式中d表示日期中的日数,m表示月份数,y表示年数。
注意:在公式中有个与其他公式不同的地方:
把一月和二月看成是上一年的十三月和十四月,例:如果是2004-1-10则换算成
2003-13-10来代入公式计算。
#include <stdio.h>
int weekday[7]={0,1,2,3,4,5,6};
int main()
{
int year,month,day,w;
while(scanf("%d%d%d",&year,&month,&day)!=EOF)
{
if(month==1 || month==2)
{
month=(month==1?13:14);//此处表示把1,2月计算到上一年的13,14月
year--;
}
w=(day+2*month+3*(month+1)/5+year+year/4-year/100+year/400+1)%7;
printf("%d\n",w);
}
}
题目描述:给你年月日,计算当天星期几
基姆拉尔森公式:W= (d+2*m+3*(m+1)/5+y+y/4-y/100+y/400+1)%7
在公式中d表示日期中的日数,m表示月份数,y表示年数。
注意:在公式中有个与其他公式不同的地方:
把一月和二月看成是上一年的十三月和十四月,例:如果是2004-1-10则换算成
2003-13-10来代入公式计算。
#include <stdio.h>
int weekday[7]={0,1,2,3,4,5,6};
int main()
{
int year,month,day,w;
while(scanf("%d%d%d",&year,&month,&day)!=EOF)
{
if(month==1 || month==2)
{
month=(month==1?13:14);//此处表示把1,2月计算到上一年的13,14月
year--;
}
w=(day+2*month+3*(month+1)/5+year+year/4-year/100+year/400+1)%7;
printf("%d\n",w);
}
}
相关文章推荐
- nyoj An problem about date(吉姆拉尔森公式)
- nyoj 219 An problem about date 日期计算 附加最优代码(基姆拉尔森公式)
- NYOJ—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
- NYOJ 219-An problem about date
- NYOJ An problem about date
- An problem about date(nyoj 219)
- NYOJ219 An problem about date 【数学】
- NYOJ 219 An problem about date(暴力)
- NYOJ-219 An problem about date
- NYOJ--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