文章

31

粉丝

1

获赞

33

访问

977

头像
日期差值 题解:

#include<iostream>
#include<cstdio>
#include<cmath>
#include<algorithm> 
#include<string>
#include<cstring>
using namespace std;
int main()
{   
    int n1 = 365, n2 = 366;
    int days1[12] = { 31,28,31,30,31,30,31,31,30,31,30,31 };
    int days2[12] = { 31,29,31,30,31,30,31,31,30,31,30,31 };
    int a, b, y1, m1, d1, y2, m2, d2, sum = 0, total = 0;
    cin >> a >> b;

    if (a > b) {
        int temp = a;
        a = b;
        b = temp;
    }
    d1 = a % 100, d2 = b % 100, m1 = a / 100 % 100, m2 = b / 100 % 100, y1 = a / 10000, y2 = b / 10000;
    if (y1 == y2) {
        sum = 0;
        if (m1 == m2) total = d2 - d1 + 1;
        else {
            bool isLeap = (y1 % 4 == 0 && y1 % 100 != 0) || (y1 % 400 == 0);
            if(isLeap){ 
                for (int i = m1 - 1; i < m2 - 1; i++) {
                    sum = sum + days2[i];
                }
            }
            else {
...
登录查看完整内容


登录后发布评论

暂无评论,来抢沙发