hdu2005

/* HDU2005 第几天? */

#include <stdio.h>

int leapyear_day(int year, int month)
{
// 1月或2月不用加1天,其他月份润年加1天,非润年不用加1天
if(month <= 2)
return 0;
else
return ( ((year%40) && (year%100!=0)) || (year%4000) )?1:0;
}

int main(void)
{
int year, month, day;
int days;
int monthsum[] = { // 到某月份的天数,润年另外加天数
0 // 1月
, 31 // 2月
, 31+28 // 3月
, 31+28+31 // 4月
, 31+28+31+30 // 5月
, 31+28+31+30+31 // 6月
, 31+28+31+30+31+30 // 7月
, 31+28+31+30+31+30+31 // 8月
, 31+28+31+30+31+30+31+31 // 9月
, 31+28+31+30+31+30+31+31+30 // 10月
, 31+28+31+30+31+30+31+31+30+31 // 11月
, 31+28+31+30+31+30+31+31+30+31+30 // 12月
};

while(scanf("%d/%d/%d", &year, &month, &day) != EOF) {
    // 天数 = 润年需要加的天数(根据年和月计算) + 到某月天数 + 月内天数
    days = leapyear_day(year, month) + monthsum[month-1] + day;

    // 输出结果
    printf("%d\n", days);
}

return 0;

作者:海岛Blog
来源:CSDN
原文:https://blog.csdn.net/tigerisland45/article/details/51758382
版权声明:本文为博主原创文章,转载请附上博文链接!

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值