题目传送门
这题初看我想着全部转化成秒然后再差分把、每一个数标记一下,再遍历重找一下写。但是这样显然比较麻烦,又想到之前写的有关地址的题,诶我直接把他们变成一个6位数然后sort一下不就完美解决了?代码非常简单, 应该每一步都一眼看出我想干嘛,就不写注释了绝对不是因为懒得写注释 qwq
#include <bits/stdc++.h>
#define sc(x) scanf("%d", &x)
#define pf(x) printf("%d", x)
#define pfn(x) printf("%d\n", x)
using namespace std;
const int N = 250000;
vector<int> v, ans;
string change(int x)
{
int s = x % 100;
x /= 100;
int m = x % 100;
x /= 100;
int h = x % 100;
string res = "";
if (h < 10)
res += "0", res += to_string(h);
else
res += to_string(h);
res += ":";
if (m < 10)
res += "0", res += to_string(m);
else
res += to_string(m);
res += ":";
if (s < 10)
res += "0", res += to_string(s);
else
res += to_string(s);
return res;
}
int main()
{
int n;
sc(n);
while (n--)
{
int x, y, z, x2, y2, z2;
scanf("%d:%d:%d - %d:%d:%d", &x, &y, &z, &x2, &y2, &z2);
getchar();
int tmp = x * 10000 + y * 100 + z, tmp1 = x2 * 10000 + y2 * 100 + z2;
v.push_back(tmp);
v.push_back(tmp1);
}
sort(v.begin(), v.end());
if (v[0] != 0)
ans.push_back(0), ans.push_back(v[0]);
for (int i = 1; i < v.size() - 1; i+=2)
{
if (v[i] != v[i + 1])
{
ans.push_back(v[i]);
ans.push_back(v[i + 1]);
}
}
if (v.back() != 235959)
{
ans.push_back(v.back());
ans.push_back(235959);
}
for (int i = 0; i < ans.size() - 1; i += 2)
{
string x1 = change(ans[i]), x2 = change(ans[i + 1]);
printf("%s - %s\n", x1.c_str(), x2.c_str());
}
return 0;
}