From f42e8dcbb78de1fa8ce89c7242e52408ff45975f Mon Sep 17 00:00:00 2001 From: Tifa <62847935+Tiphereth-A@users.noreply.github.com> Date: Mon, 17 Oct 2022 20:55:18 +0800 Subject: [PATCH] problem(A1049): std --- problems/A/A1049/std.cpp | 52 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 52 insertions(+) create mode 100644 problems/A/A1049/std.cpp diff --git a/problems/A/A1049/std.cpp b/problems/A/A1049/std.cpp new file mode 100644 index 0000000..1583893 --- /dev/null +++ b/problems/A/A1049/std.cpp @@ -0,0 +1,52 @@ +#include +#include +#include + +using namespace std; + +struct TimeRange { + int time_start, time_end; + + TimeRange(string const &s): time_start(0), time_end(0) { + int hh_start = stoi(s.substr(0, 2)); + int mm_start = stoi(s.substr(3, 2)); + int ss_start = stoi(s.substr(6, 2)); + + int hh_end = stoi(s.substr(9, 2)); + int mm_end = stoi(s.substr(12, 2)); + int ss_end = stoi(s.substr(15, 2)); + + time_start = hh_start * 3600 + mm_start * 60 + ss_start; + time_end = hh_end * 3600 + mm_end * 60 + ss_end; + } +}; + +const int N = 24 * 60 * 60 + 1; +int diff[N]; + +int main() { + int T; + cin >> T; + cout << right << setfill('0'); + while (T--) { + for (int i = 0; i < N; ++i) diff[i] = 0; + int n; + cin >> n; + string s; + for (int j = 0; j < n; ++j) { + cin >> s; + TimeRange tr(s); + ++diff[tr.time_start]; + --diff[tr.time_end + 1]; + } + for (int i = 1; i < N; ++i) diff[i] += diff[i - 1]; + int ans = 0; + for (int i = 0; i < N - 1; ++i) ans += !diff[i]; + int ss = ans % 60; + ans /= 60; + int mm = ans % 60; + ans /= 60; + int hh = ans; + cout << setw(2) << hh << ':' << setw(2) << mm << ':' << setw(2) << ss << '\n'; + } +}