程式碼很爛。
#include <bits/stdc++.h>
using namespace std;
struct node {
int start[10];
int end[10];
}s[100000];
bool cmp(node n1,node n2) {
for (int i = 0; i < 3; i++) {
if (n1.start[i] != n2.start[i]) {
return n1.start[i] < n2.start[i];
}
}
return 1;
}
void print(node n1,node n2) {
printf("%02d:%02d:%02d - %02d:%02d:%02d\n", n1.end[0], n1.end[1], n1.end[2],
n2.start[0], n2.start[1], n2.start[2]);
}
int main() {
int k;
cin >> k;
s[0].end[0] = 0;
s[0].end[1] = 0;
s[0].end[2] = 0;
for (int i = 1; i <= k; i++) {
int a1, b1, c1, a2, b2, c2;
scanf("%d:%d:%d - %d:%d:%d", &a1, &b1, &c1, &a2, &b2, &c2);
s[i].start[0] = a1;
s[i].start[1] = b1;
s[i].start[2] = c1;
s[i].end[0] = a2;
s[i].end[1] = b2;
s[i].end[2] = c2;
}
s[k+1].start[0] = 23;
s[k+1].start[1] = 59;
s[k+1].start[2] = 59;
sort(s+1, s + k+1, cmp);
node pre = s[0];
for (int i = 1; i <= k+1; i++) {
int flag = 0;
for (int j = 0; j < 3; j++) {
if (s[i].start[j] != pre.end[j]) {
flag = 1;
break;
}
}
if (flag) {//輸出
print(pre,s[i]);
}
pre = s[i];
}
return 0;
}