团体程序设计天梯赛
L2-042 老板的作息表
模拟,对所有时间排序,找出缺失的时间。注意边界时间的处理。
#include <bits/stdc++.h>
using namespace std;
struct tspan{
int hh1, mm1, ss1;
int hh2, mm2, ss2;
bool operator < (const tspan &t) const{
if(hh1 != t.hh1) return hh1 < t.hh1;
if(mm1 != t.mm1) return mm1 < t.mm1;
return ss1 < t.ss1;
}
};
int n;
vector<tspan> ts;
int main(){
cin >> n;
int a, b, c, d, e, f;
for(int i = 0; i <= n - 1; i ++){
scanf("%d:%d:%d - %d:%d:%d", &a, &b, &c, &d, &e, &f);
tspan tt = {a, b, c, d, e, f};
ts.push_back(tt);
}
sort(ts.begin(), ts.end());
int s = (int)ts.size();
int sthh = ts[0].hh1, stmm = ts[0].mm1, stss = ts[0].ss1;
int edhh = ts[0].hh2, edmm = ts[0].mm2, edss = ts[0].ss2;
if(sthh != 0 || stmm != 0 || stss != 0)
printf("00:00:00 - %02d:%02d:%02d\n", sthh, stmm, stss);
for(int i = 1; i <= s - 1; i ++){
if(edhh != ts[i].hh1 || edmm != ts[i].mm1 || edss != ts[i].ss1)
printf("%02d:%02d:%02d - %02d:%02d:%02d\n", edhh, edmm, edss, ts[i].hh1, ts[i].mm1, ts[i].ss1);
edhh = ts[i].hh2, edmm = ts[i].mm2, edss = ts[i].ss2;
}
if(ts[s - 1].hh2 != 23 || ts[s - 1].mm2 != 59 || ts[s - 1].ss2 != 59)
printf("%02d:%02d:%02d - 23:59:59\n", ts[s - 1].hh2, ts[s - 1].mm2, ts[s - 1].ss2);
return 0;
}