OJ题-计算日期到天数转换

#include <iostream>
using namespace std;

int main()
{
    int a, b, c;
    int out = 0;
    while (cin >> a >> b >> c) { // 注意 while 处理多个 case
        if (a % 4 == 0 && a % 100 != 0)
        {
            while (b--)
            {
                if (b == 1)
                {
                    out += 31;
                }
                else if (b == 2)
                {
                    out += 29;
                }
                else if (b == 3)
                {
                    out += 31;
                }
                else if (b == 4)
                {
                    out += 30;
                }
                else if (b == 5)
                {
                    out += 31;
                }
                else if (b == 6)
                {
                    out += 30;
                }
                else if (b == 7)
                {
                    out += 31;
                }
                else if (b == 8)
                {
                    out += 31;
                }
                else if (b == 9)
                {
                    out += 30;
                }
                else if (b == 10)
                {
                    out += 31;
                }
                else if (b == 11)
                {
                    out += 30;
                }
                else if (b == 12)
                {
                    out += 31;
                }
            }
            out += c;
            cout << out;
        }
        else 
        {
            while (b--)
            {
                if (b == 1)
                {
                    out += 31;
                }
                else if (b == 2)
                {
                    out += 28;
                }
                else if (b == 3)
                {
                    out += 31;
                }
                else if (b == 4)
                {
                    out += 30;
                }
                else if (b == 5)
                {
                    out += 31;
                }
                else if (b == 6)
                {
                    out += 30;
                }
                else if (b == 7)
                {
                    out += 31;
                }
                else if (b == 8)
                {
                    out += 31;
                }
                else if (b == 9)
                {
                    out += 30;
                }
                else if (b == 10)
                {
                    out += 31;
                }
                else if (b == 11)
                {
                    out += 30;
                }
                else if (b == 12)
                {
                    out += 31;
                }
            }
            out += c;
            cout << out;
        }
    }
}
// 64 位输出请用 printf("%lld")

先if判断闰年,再用while循环计算月份的天数最后加上日期的天数

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值