当前位置:   article > 正文

天梯赛-L2-042 老板的作息表_天梯赛老板休息表

天梯赛老板休息表

在这里插入图片描述
在这里插入图片描述
思路:开个结构体模拟即可,然后用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;
}
  • 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
声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/知新_RL/article/detail/408547
推荐阅读
相关标签
  

闽ICP备14008679号