当前位置:网站首页>L2-042 老板的作息表
L2-042 老板的作息表
2022-08-05 10:28:00 【一条小小yu】
天梯赛的时候不知道在干什么,朋友wqh说我结构体排序不行哭了。
新浪微博上有人发了某老板的作息时间表,表示其每天 4:30 就起床了。但立刻有眼尖的网友问:这时间表不完整啊,早上九点到下午一点干啥了?
本题就请你编写程序,检查任意一张时间表,找出其中没写出来的时间段。
输入格式:
输入第一行给出一个正整数 N,为作息表上列出的时间段的个数。随后 N 行,每行给出一个时间段,格式为:
hh:mm:ss - hh:mm:ss
其中 hh、mm、ss 分别是两位数表示的小时、分钟、秒。第一个时间是开始时间,第二个是结束时间。题目保证所有时间都在一天之内(即从 00:00:00 到 23:59:59);每个区间间隔至少 1 秒;并且任意两个给出的时间区间最多只在一个端点有重合,没有区间重叠的情况。
输出格式:
按照时间顺序列出时间表中没有出现的区间,每个区间占一行,格式与输入相同。题目保证至少存在一个区间需要输出。
输入样例:
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解法1:
#include<bits/stdc++.h>
using namespace std;
struct node
{
int a,b,c,x,y,z;
} a[100010];
bool cmp(node m,node n)
{
if(m.a==n.a)
{
if(m.b==n.b)
{
return m.c<n.c;
}
return m.b<n.b;
}
return m.a<n.a;
}
int main()
{
int n;
cin>>n;
for(int i=1; i<=n; i++)
scanf("%d:%d:%d - %d:%d:%d",&a[i].a,&a[i].b,&a[i].c,&a[i].x,&a[i].y,&a[i].z);
sort(a+1,a+n+1,cmp);
a[0]= {0,0,0,0,0,0},a[n+1]= {23,59,59,0,0,0};
for(int i=1; i<=n+1; i++)
if(a[i-1].x==a[i].a&&a[i-1].y==a[i].b&&a[i-1].z==a[i].c);
else printf("%02d:%02d:%02d - %02d:%02d:%02d\n",a[i-1].x,a[i-1].y,a[i-1].z,a[i].a,a[i].b,a[i].c);
}
解法2:
#include <bits/stdc++.h>
using namespace std;
int n;
vector<pair<string,string>> q;
int main(){
cin >> n;
while(n -- ){
string a, b, c;
cin >> a >> b >> c;
q.push_back({a, c});
}
q.push_back({"", "00:00:00"});
q.push_back({"23:59:59", ""});
sort(q.begin(), q.end());
int m = q.size();
for (int i = 0; i < m - 1; i ++ )
if (q[i].second != q[i + 1].first)
cout << q[i].second << " - " << q[i + 1].first << endl;
return 0;
}边栏推荐
- This notebook of concurrent programming knowledge points strongly recommended by Ali will be a breakthrough for you to get an offer from a big factory
- nyoj754 黑心医生 结构体优先队列
- uniapp 连接ibeacon
- 企业的数字化转型到底是否可以买来?
- 力扣(LeetCode)216. 组合总和 III(2022.08.04)
- Data Middle Office Construction (10): Data Security Management
- uniapp connect ibeacon
- three.js debugging tool dat.gui use
- 60行从零开始自己动手写FutureTask是什么体验?
- 【Office】Microsoft Office下载地址合集(微软官方原版离线安装下载)
猜你喜欢

告白数字化转型时代:麦聪软件以最简单的方式让企业把数据用起来

Technical dry goods | Hausdorff distance for image segmentation based on MindSpore

数据可视化(一)

高质量 DeFi 应用构建指南,助力开发者玩转 DeFi Summer

MySQL事务

PCB layout must know: teach you to correctly lay out the circuit board of the op amp

【温度预警程序de开发】事件驱动模型实例运用

教你本地编译运行一个IDEA插件,在IDEA里聊天、下棋、斗地主!

多线程(进阶) - 2.5w字总结

如何选币与确定对应策略研究
随机推荐
Chapter 4: In the activiti process, variable transmission and acquisition process variables, setting and acquiring multiple process variables, setting and acquiring local process variables "recommende
Getting started with Polkadot parachain development, this article is enough
E-sports, convenience, efficiency, security, key words for OriginOS functions
第四章:activiti RuntimeService设置获和取流程变量,及与taskService的区别,开始和完成任务时设置流程变量[通俗易懂]
基于MindSpore高效完成图像分割,实现Dice!
Confessing in the era of digital transformation: Mai Cong Software allows enterprises to use data in the easiest way
High-quality DeFi application building guide to help developers enjoy DeFi Summer
Chapter 5: Activiti process shunting judgment, judging to go to different task nodes
华为轻量级神经网络架构GhostNet再升级,GPU上大显身手的G-GhostNet(IJCV22)
电气工程的标准是什么
第八章:activiti多用户任务分配
秘乐短视频挖矿系统开发详情
Huawei's lightweight neural network architecture GhostNet has been upgraded again, and G-GhostNet (IJCV22) has shown its talents on the GPU
[强网杯2022]WP-UM
【Unity】【UGUI】【在屏幕上显示文本】
012年通过修补_sss_提高扩散模型效率
【综合类型第 35 篇】程序员的七夕浪漫时刻
Go compilation principle series 6 (type checking)
字节一面:TCP 和 UDP 可以使用同一个端口吗?
Brief Analysis of WSGI Protocol