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>
用户输出
59
59
1537
82527
1032927
21164127
17902896185
-1
-1
-1
-1
-1
-1
315537897599
系统信息
Exited with return code 0
编号 | 题目 | 状态 | 分数 | 总时间 | 内存 | 代码 / 答案文件 | 提交者 | 提交时间 |
---|---|---|---|---|---|---|---|---|
#100490 | #112. czq的时间间隔 | Accepted | 100 | 41 ms | 620 K | C++ 11 / 5.5 K | wrh123 | 2023-07-30 9:21:30 |
#include <iostream>
#include <cstring>
#include <iomanip>
#include <math.h>
#include <climits>
using namespace std;
bool isright(int year1, int month1, int day1, int hour1, int minute1, int second1, int year2, int month2,
int day2, int hour2, int minute2, int second2) {
if (year1 < 1 || year2 < 1) {
return false;
}
if (month1 < 1 || month1 > 12 || month2 < 1 || month2 > 12) {
return false;
}
if (day1 < 1 || day1 > 31 || day2 < 1 || day2 > 31) {
return false;
}
if (((month1 == 4 || month1 == 6 || month1 == 9 || month1 == 11) && day1 == 31) ||
((month2 == 4 || month2 == 6 || month2 == 9 || month2 == 11) && day2 == 31)) {
return false;
}
if (((year1 % 4 == 0 && year1 % 100 != 0) || year1 % 400 == 0) ||
((year2 % 4 == 0 && year2 % 100 != 0) || year2 % 400 == 0)) {
if ((month1 == 2 && day1 > 29) || (month2 == 2 && day2 > 29)) {
return false;
}
}
if (((year1 % 4 != 0 || (year1 % 100 == 0 && year1 % 400 != 0)) && month1 == 2 && day1 >= 29) ||
((year2 % 4 != 0 || (year2 % 100 == 0 && year2 % 400 != 0)) && month2 == 2 && day2 >= 29)) {
return false;
}
if (hour1 < 0 || hour1 >= 24 || hour2 < 0 || hour2 >= 24) {
return false;
}
if (minute1 < 0 || minute1 >= 60 || minute2 < 0 || minute2 >= 60) {
return false;
}
if (second1 < 0 || second1 >= 60 || second2 < 0 || second2 >= 60) {
return false;
}
return true;
}
long long CountDays(int year, int month, int day) {
long long result = 0;
int temp = year - 1;
result += (temp / 400) * (97 * 366 + 303 * 365);
result += (temp % 400) / 100 * (24 * 366 + 76 * 365);
result += (temp % 100) / 4 * (366 + 3 * 365);
result += (temp % 4) * 365;
for (int i = 1; i <= 12; ++i) {
if (i < month) {
switch (i) {
case 1: {
result += 31;
break;
}
case 2: {
if ((year % 4 == 0 && year % 100 != 0) || year % 400 == 0) {
result += 29;
} else {
result += 28;
}
break;
}
case 3: {
result += 31;
break;
}
case 4: {
result += 30;
break;
}
case 5: {
result += 31;
break;
}
case 6: {
result += 30;
break;
}
case 7: {
result += 31;
break;
}
case 8: {
result += 31;
break;
}
case 9: {
result += 30;
break;
}
case 10: {
result += 31;
break;
}
case 11: {
result += 30;
break;
}
case 12: {
result += 31;
break;
}
}
}
}
result += day;
return result;
}
long long CountSeconds(int hour, int minute, int second) {
long long result = 0;
result += hour * 3600;
result += minute * 60;
result += second;
return result;
}
int main() {
int n;
cin >> n;
long long result[n] = { 0 };
int year1, month1, day1, hour1, minute1, second1, year2, month2, day2, hour2, minute2, second2;
for (int i = 0; i < n; ++i) {
cin >> year1;
cin.get();
cin >> month1;
cin.get();
cin >> day1;
cin >> hour1;
cin.get();
cin >> minute1;
cin.get();
cin >> second1;
cin >> year2;
cin.get();
cin >> month2;
cin.get();
cin >> day2;
cin >> hour2;
cin.get();
cin >> minute2;
cin.get();
cin >> second2;
if (isright(year1, month1, day1, hour1, minute1, second1, year2, month2, day2, hour2, minute2,
second2)) {
long long days1, days2;
days1 = CountDays(year1, month1, day1);
days2 = CountDays(year2, month2, day2);
long long seconds = 0;
long long seconds1, seconds2;
seconds1 = CountSeconds(hour1, minute1, second1);
seconds2 = CountSeconds(hour2, minute2, second2);
if (days1 > days2) {
seconds = (days1 - days2) * 24 * 3600;
seconds += seconds1;
seconds -= seconds2;
} else if (days1 < days2) {
seconds = (days2 - days1) * 24 * 3600;
seconds += seconds2;
seconds -= seconds1;
} else {
if (seconds1 > seconds2) {
seconds = (seconds1 - seconds2);
} else {
seconds = (seconds2 - seconds1);
}
}
result[i] = seconds;
} else {
result[i] = -1;
}
}
for (int i = 0; i < n; ++i) {
cout << result[i] << endl;
}
return 0;
}
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>
用户输出
59
59
1537
82527
1032927
21164127
17902896185
-1
-1
-1
-1
-1
-1
315537897599
系统信息
Exited with return code 0
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>
-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