赞
踩
一道基础的模拟题。
cmp排序hh:mm:ss类型时间。
比较hh:mm:ss类型的时间。
注意头和尾部数据的处理。
#include<bits/stdc++.h>
using namespace std;
struct node{
int h1,m1,s1,h2,m2,s2;
};
bool cmp(node a, node b)
{
if(a.h1 == b.h1)
{
if(a.m1 == b.m1)
{
return a.s1 < b.s1;
}
return a.m1 < b.m1;
}
return a.h1 < b.h1;
}
int main()
{
node t[100010];
int n;
cin >> n;
for(int i=0,h1,h2,m1,m2,s1,s2;i<n;i++)
{
scanf("%d:%d:%d - %d:%d:%d",
&t[i].h1,&t[i].m1,&t[i].s1,
&t[i].h2,&t[i].m2,&t[i].s2);
}
sort(t,t+n,cmp);
if(!(t[0].h1==0&&t[0].m1==0&&t[0].s1==0))
printf("%02d:%02d:%02d - %02d:%02d:%02d\n",
0,0,0,t[0].h1,t[0].m1,t[0].s1);
int f = 1;
for(int i=0;i<n-1;i++)
{
f = 1;
if(t[i].h2 == t[i+1].h1)
{
if(t[i].m2==t[i+1].m1)
{
if(t[i].s2 == t[i+1].s1)
{
;
}
else f = 0;
}
else f = 0;
}
else f = 0;
if(!f) printf("%02d:%02d:%02d - %02d:%02d:%02d\n",
t[i].h2,t[i].m2,t[i].s2,
t[i+1].h1,t[i+1].m1,t[i+1].s1);
}
if(!(t[n-1].h2==23&&t[n-1].m2==59&&t[n-1].s2==59))
printf("%02d:%02d:%02d - %02d:%02d:%02d\n",
t[n-1].h2,t[n-1].m2,t[n-1].s2,
23,59,59);
return 0;
}
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。