思路:开个结构体模拟即可,然后用scanf会简单点,水题。
#include <bits/stdc++.h>
using namespace std;
const int maxn = 1e5+10;
struct node{
int hh,mm,ss;
int hhx,mmx,ssx;
}t[maxn];
bool cmp(node x, node y){
if(x.hh==y.hh){
if(x.mm==y.mm) return x.ss<y.ss;
return x.mm<y.mm;
}
return x.hh<y.hh;
}
int n;
int main(){
cin >> n;
for(int i=1; i<=n; i++){
scanf("%d:%d:%d - %d:%d:%d",&t[i].hh,&t[i].mm,&t[i].ss,&t[i].hhx,&t[i].mmx,&t[i].ssx);
}
//puts("");
sort(t+1,t+1+n,cmp);
int h=0,m=0,s=0;
for(int i=1; i<=n; i++){
if(t[i].hh!=h||t[i].mm!=m||t[i].ss!=s){
printf("%02d:%02d:%02d - %02d:%02d:%02d\n",h,m,s,t[i].hh,t[i].mm,t[i].ss);
h=t[i].hhx,m=t[i].mmx,s=t[i].ssx;
}
else{
h=t[i].hhx,m=t[i].mmx,s=t[i].ssx;
}
}
if(h!=23||m!=59||s!=59) printf("%02d:%02d:%02d - 23:59:59\n",h,m,s);
return 0;
}