当前位置:   article > 正文

程序设计天梯赛 L2-042 老板的作息表 模拟和数据处理_天梯赛老板的作息表

天梯赛老板的作息表

一道基础的模拟题。
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;
}
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24
  • 25
  • 26
  • 27
  • 28
  • 29
  • 30
  • 31
  • 32
  • 33
  • 34
  • 35
  • 36
  • 37
  • 38
  • 39
  • 40
  • 41
  • 42
  • 43
  • 44
  • 45
  • 46
  • 47
  • 48
  • 49
  • 50
  • 51
  • 52
  • 53
  • 54
  • 55
  • 56
  • 57
  • 58
  • 59
声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/Monodyee/article/detail/408561
推荐阅读
相关标签
  

闽ICP备14008679号