【codeup墓地】1928: 日期差值

原题链接

#include<algorithm>
#include<iostream>
#include<cstdio>
#include<cstring>
#include <ctime>
#include <cmath>
#include <vector>
#include <set>
#include <map>
#include <stack>
#include <queue>
using namespace std;

typedef struct Data
{
    int year, month, day;
    Data(){}
    Data(int a, int b, int c)
    {
        year = a, month = b, day = c;
    }
}Data;
Data A, B;

bool isLeapYaer(int year)//判断是不是闰年
{
    return (year%400 == 0 || year%4 == 0 && year%100);
}

int main()
{
    int month[13] = {0, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
    int time1, time2;
    while(scanf("%d %d", &time1, &time2) != EOF)
    {
        int cnt = 1;
        if(time1 > time2) swap(time1, time2);
        A = Data(time1/10000, time1%10000/100, time1%100);
        B = Data(time2/10000, time2%10000/100, time2%100);
        while(A.year < B.year || A.month < B.month || A.day < B.day)
        {
            int flag = isLeapYaer(A.year);
            A.day++, cnt++;
            if(A.month == 2 && ( flag && A.day == 30 || !flag && A.day == 29)
               || A.month != 2 && A.day == month[A.month]+1) A.day = 1, A.month++;
            if(A.month == 13) A.month = 1, A.year++;
        }
        printf("%d\n", cnt);
    }
	return 0;
}


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值