3 条题解

  • 0
    @ 2024-08-28 11:30:26

    要不要把闰秒也考虑进去?(doge)

    #include<iostream>
    using namespace std;
    int a[14] = {0, 1, -2, 1, 0, 1, 0, 1, 1, 0, 1, 0, 1};
    int day(bool r, int m1, int d1, int m2, int d2){
        int ans;
        if(r)a[2] = -1;
        else a[2] = -2;
        ans = (m2-m1)*30+d2-d1;
        for(int i = m1; i < m2; i++)ans += a[i];
        return ans;
    }
    bool run(int y){
        return ((y % 400 == 0) || ((y & 3) == 0 && !(y % 100 == 0)));
    }
    int main(){
        ios::sync_with_stdio(false);
        int y1, m1, d1, h1, min1, s1, y2, m2, d2, h2, min2, s2, cnt = 0, days;
        cin >> y1 >> m1 >> d1 >> h1 >> min1 >> s1 >> y2 >> m2 >> d2 >> h2 >> min2 >> s2;
        for(int i = y1; i <= y2; i++){
            if(run(i))cnt++;
        }
        days = (y2-y1+1)*365 + cnt - day(run(y1), 1, 1, m1, d1) - day(run(y2), m2, d2, 12, 31) - 1;
        cout << days*86400 - (3600*h1+60*min1+s1) + (3600*h2+60*min2+s2);
    }
    
  • -1
    @ 2019-03-31 13:35:24
    #include <iostream>
    using namespace std;
    class DateTime
    {
        int year, month, day, hour, minute, second;
    public:
        void init(int y, int mon, int d, int h, int min, int s)
        {
    
            year = y;
            month = mon;
            day = d;
            hour = h;
            minute = min;
            second = s;
        }
        int isLeapYear()
        {
            if (year % 400 == 0 || (year % 4 == 0 && year % 100 != 0))
                return 1;
            else
                return 0;
        }
        int isLeapYear(int i)
        {
            if (i % 400 == 0 || (i % 4 == 0 && i % 100 != 0))
                return 1;
            else
                return 0;
        }
        int daytoBegin()
        {
            int Month[13] = { 0,31,28 + isLeapYear(),31,30,31,30,31,31,30,31,30,31 };
            if (month == 1)
                return day;
            int ans = day;
            while (month > 1)
            {
                ans += Month[month - 1];
                month--;
            }
            return ans;
        }
        int secondtoBegin()
        {
            return 60 * 60 * 24 * daytoBegin() - (60 - second) - 60 * (59 - minute) - 60 * 60 * (23 - hour);
        }
        int GapYearSecond(int y)
        {
            if (y - year >= 1)
            {
                int ans = 365 * (y - year - 1);
                for (int i = year + 1; i < y; i++)
                {
                    if (isLeapYear(i))
                        ans++;
                }
                return ans * 60 * 60 * 24;
            }
            else
            {
                return -(365 + isLeapYear(year)) * 60 * 60 * 24;
            }
        }
    };
    int isLeapYear(int i)
    {
        if (i % 400 == 0 || (i % 4 == 0 && i % 100 != 0))
            return 1;
        else
            return 0;
    }
    int main()
    {
        int y1, mon1, d1, h1, min1, s1;
        cin >> y1 >> mon1 >> d1 >> h1 >> min1 >> s1;
        int y2, mon2, d2, h2, min2, s2;
        cin >> y2 >> mon2 >> d2 >> h2 >> min2 >> s2;
        DateTime t1, t2;
        t1.init(y1, mon1, d1, h1, min1, s1);
        t2.init(y2, mon2, d2, h2, min2, s2);
        cout << 60 * 60 * 24 * (365 + isLeapYear(y1)) - t1.secondtoBegin() + t1.GapYearSecond(y2) + t2.secondtoBegin();
        return 0;
    }
    
  • -4

    #include <iostream>
    using namespace std;
    class DateTime
    {
    int year, month, day, hour, minute, second;
    public:
    void init(int y, int mon, int d, int h, int min, int s)
    {

    year = y;
    month = mon;
    day = d;
    hour = h;
    minute = min;
    second = s;
    }
    int isLeapYear()
    {
    if (year % 400 == 0 || (year % 4 == 0 && year % 100 != 0))
    return 1;
    else
    return 0;
    }
    int isLeapYear(int i)
    {
    if (i % 400 == 0 || (i % 4 == 0 && i % 100 != 0))
    return 1;
    else
    return 0;
    }
    int daytoBegin()
    {
    int Month[13] = { 0,31,28 + isLeapYear(),31,30,31,30,31,31,30,31,30,31 };
    if (month == 1)
    return day;
    int ans = day;
    while (month > 1)
    {
    ans += Month[month - 1];
    month--;
    }
    return ans;
    }
    int secondtoBegin()
    {
    return 60 * 60 * 24 * daytoBegin() - (60 - second) - 60 * (59 - minute) - 60 * 60 * (23 - hour);
    }
    int GapYearSecond(int y)
    {
    if (y - year >= 1)
    {
    int ans = 365 * (y - year - 1);
    for (int i = year + 1; i < y; i++)
    {
    if (isLeapYear(i))
    ans++;
    }
    return ans * 60 * 60 * 24;
    }
    else
    {
    return -(365 + isLeapYear(year)) * 60 * 60 * 24;
    }
    }
    };
    int isLeapYear(int i)
    {
    if (i % 400 == 0 || (i % 4 == 0 && i % 100 != 0))
    return 1;
    else
    return 0;
    }
    int main()
    {
    int y1, mon1, d1, h1, min1, s1;
    cin >> y1 >> mon1 >> d1 >> h1 >> min1 >> s1;
    int y2, mon2, d2, h2, min2, s2;
    cin >> y2 >> mon2 >> d2 >> h2 >> min2 >> s2;
    DateTime t1, t2;
    t1.init(y1, mon1, d1, h1, min1, s1);
    t2.init(y2, mon2, d2, h2, min2, s2);
    cout << 60 * 60 * 24 * (365 + isLeapYear(y1)) - t1.secondtoBegin() + t1.GapYearSecond(y2) + t2.secondtoBegin();
    return 0;
    }
    Copy

  • 1

信息

ID
1008
难度
3
分类
(无)
标签
递交数
266
已通过
130
通过率
49%
被复制
9
上传者