赞
踩
- 8
- 13:00:00 - 18:00:00
- 00:00:00 - 01:00:05
- 08:00:00 - 09:00:00
- 07:10:59 - 08:00:00
- 01:00:05 - 04:30:00
- 06:30:00 - 07:10:58
- 05:30:00 - 06:30:00
- 18:00:00 - 19:00:00
- 04:30:00 - 05:30:00
- 07:10:58 - 07:10:59
- 09:00:00 - 13:00:00
- 19:00:00 - 23:59:59
考察 : 数据结构与排序 |
注意 : 早上开始00:00:00,晚上结束23:59:59 |
思路 :以每一个时间段为'对象'创建数据结构 其属性为: 开始与结束对应的时分秒 接着按照开始时间将每个时间段升序排序 最后逐个判断两个相邻时间段结束跟开始时间是否相同即可 |
- #include<bits/stdc++.h>
- using namespace std;
- struct T{
- int a,b,c,d,e,f;
- }t[52000];
- bool cmp(T x,T y){
- if(x.a!=y.a) return x.a < y.a;
- if(x.b!=y.b) return x.b < y.b;
- return x.c < y.c;
- }
- int main()
- {
- int N;
- cin >> N;
- for(int z=0;z<N;z++) scanf("%d:%d:%d - %d:%d:%d",&t[z].a,&t[z].b,&t[z].c,&t[z].d,&t[z].e,&t[z].f);
- sort(t,t+N,cmp);
-
- if(t[0].a!=0 || t[0].b!=0 || t[0].c!=0 ) printf("00:00:00 - %02d:%02d:%02d\n",t[0].a,t[0].b,t[0].c);
- for(int z=1;z<N;z++) {
- if(t[z].a != t[z-1].d || t[z].b!=t[z-1].e || t[z].c != t[z-1].f){
- printf("%02d:%02d:%02d - %02d:%02d:%02d\n",t[z-1].d,t[z-1].e,t[z-1].f,t[z].a,t[z].b,t[z].c);
- }
- }
- if(t[N-1].d!=23 || t[N-1].e!=59 || t[N-1].f!=59 ) printf("%02d:%02d:%02d - 23:59:59\n",t[N-1].d,t[N-1].e,t[N-1].f);
-
- return 0;
- }

-
- #include<iostream>
- #include <vector>
- #include <algorithm>
- using namespace std;
- struct OP{
- int hour1=0,hour2=0,minute1=0,minute2=0,second1=0,second2=0;
- long start=0,end=0;
- };
- int cmp(OP A,OP B){
- return A.start <B.start;
- }
-
- int main()
- {
- int num; //区间数
- vector<OP> table;
- cin >> num;
- OP a;
- for(int z=0;z<num;z++){
- scanf("%d:%d:%d - %d:%d:%d",&a.hour1,&a.minute1,&a.second1,&a.hour2,&a.minute2,&a.second2);
- a.start = a.hour1*10000+a.minute1*100+a.second1;
- a.end = a.hour2*10000+a.minute2*100+a.second2;
- table.push_back(a);
- }
-
- sort(table.begin(),table.end(),cmp);
- OP now;
- int nn = table.size();
- for(int i=0;i<nn;i++){
- a = table[i];
- if(a.start!=now.end){
- printf("%02d:%02d:%02d - %02d:%02d:%02d\n",now.hour2,now.minute2,now.second2,a.hour1,a.minute1,a.second1);
- }
- now = a;
- }
-
- if(now.end!=235959)
- {
- printf("%02d:%02d:%02d - 23:59:59\n",now.hour2,now.minute2,now.second2);
- }
-
- return 0;
- }

Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。