编号 题目 状态 分数 总时间 内存 代码 / 答案文件 提交者 提交时间
#68655 #112. czq的时间间隔 Accepted 100 47 ms 384 K C++ / 2.4 K 该起什么名字 2022-04-04 4:40:05
显示原始代码
#include <cstdio>
#include <iostream>
using namespace std;

struct Time {
    int year, month, date, h, min, s;
} a, b;

void read(Time* x) { scanf("%d/%d/%d %d:%d:%d", &x->year, &x->month, &x->date, &x->h, &x->min, &x->s); }

int r(Time* x) {
    if (x->year % 4 == 0 && x->year % 100 != 0 || x->year % 400 == 0)
        return 1;
    return 0;
}

int r(int x) {
    if (x % 4 == 0 && x % 100 != 0 || x % 400 == 0)
        return 1;
    return 0;
}

int days(Time* x) {
    int m[] = { 0, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 };
    if (x->month != 2)
        return m[x->month];
    return m[2] + r(x);
}

int days(Time* x, int n) {
    int m[] = { 0, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 };
    if (n != 2)
        return m[n];
    return m[2] + r(x);
}

bool check(Time* x) {
    if (x->month > 12)
        return false;
    if (x->year == 0 || x->month == 0 || x->date == 0)
        return false;
    if (x->date > days(x))
        return false;
    if (x->h >= 24 || x->min >= 60 || x->s >= 60)
        return false;
    return true;
}

int num(Time* x) {
    int sum = 0;
    for (int i = 1; i < x->month; i++) sum += days(x, i);
    sum += x->date;
    return sum;
}

int cmp(Time* a, Time* b) {
    if (a->year > b->year)
        return 1;
    if (a->year < b->year)
        return -1;
    if (a->month > b->month)
        return 1;
    if (a->month < b->month)
        return -1;
    if (a->date > b->date)
        return 1;
    if (a->date < b->date)
        return -1;
    if (a->h > b->h)
        return 1;
    if (a->h < b->h)
        return -1;
    if (a->min > b->min)
        return 1;
    if (a->min < b->min)
        return -1;
    if (a->s > b->s)
        return 1;
    if (a->s < b->s)
        return -1;
    return 0;
}

int main() {
    int t;
    cin >> t;
    for (int i = 0; i < t; i++) {
        read(&a);
        read(&b);
        if (!check(&a) || !check(&b)) {
            cout << "-1" << endl;
            continue;
        }
        if (cmp(&a, &b) == 1) {
            Time t;
            t = a;
            a = b;
            b = t;
        }
        long long ans = 0;
        for (int j = a.year; j < b.year; j++) ans += 365 + r(j);
        ans += num(&b) - num(&a);
        ans = ans * 24 + b.h - a.h;
        ans = ans * 60 + b.min - a.min;
        ans = ans * 60 + b.s - a.s;
        cout << ans << endl;
    }
    return 0;
}
子任务 #1
Accepted
得分:100
测试点 #1
Accepted
得分:100
用时:2 ms
内存:372 KiB

输入文件(1.in

14
2020/08/22 23:48:00 2020/08/22 23:48:59
2020/08/22 23:48:59 2020/08/22 23:48:00
2020/08/22 23:22:
<463 bytes omitted>

答案文件(1.out

59
59
1537
82527
1032927
21164127
17902896185
-1
-1
-1
-1
-1
-1
315537897599

用户输出

59
59
1537
82527
1032927
21164127
17902896185
-1
-1
-1
-1
-1
-1
315537897599

系统信息

Exited with return code 0
测试点 #2
Accepted
得分:100
用时:45 ms
内存:384 KiB

输入文件(2.in

10000
5348/13/26 20:09:36 5809/10/09 11:17:33
8951/13/09 02:54:35 1245/10/20 19:37:36
7524/01/04 20:
<399906 bytes omitted>

答案文件(2.out

-1
-1
52181193949
167527773820
11151421677
176367406636
34137847390
71087537213
156479412870
<102130 bytes omitted>

用户输出

-1
-1
52181193949
167527773820
11151421677
176367406636
34137847390
71087537213
156479412870
-1
-1
81508312928
163816674890
-1
6
<92102 bytes omitted>

系统信息

Exited with return code 0