当前位置:网站首页>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;
}
边栏推荐
- 语音社交软件开发——充分发挥其价值
- 【MindSpore Easy-Diantong Robot-01】You may have seen many knowledge quiz robots, but this one is a bit different
- static linking and dynamic linking
- 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
- 这份阿里强推的并发编程知识点笔记,将是你拿大厂offer的突破口
- Chapter 5: Multithreaded Communication—wait and notify
- 数据中台建设(十):数据安全管理
- Confessing in the era of digital transformation: Mai Cong Software allows enterprises to use data in the easiest way
- First Decentralized Heist?Loss of nearly 200 million US dollars: analysis of the attack on the cross-chain bridge Nomad
- 深入理解 Istio 流量管理的超时时间设置
猜你喜欢
The century-old Nordic luxury home appliance brand ASKO smart wine cabinet in the three-temperature area presents the Chinese Valentine’s Day, and tastes the love of the delicacy
数据中台建设(十):数据安全管理
电气工程的标准是什么
还在找网盘资源吗?快点收藏如下几个值得收藏的网盘资源搜索神器吧!
Getting started with Polkadot parachain development, this article is enough
Opencv图像缩放和平移
Use KUSTO query statement (KQL) to query LOG on Azure Data Explorer Database
高质量 DeFi 应用构建指南,助力开发者玩转 DeFi Summer
JS逆向入门学习之回收商网,手机号码简易加密解析
PCB layout must know: teach you to correctly lay out the circuit board of the op amp
随机推荐
项目成本控制如何帮助项目成功?
LeetCode 216. Combined Sum III (2022.08.04)
STM32+ULN2003 drives 28BYJ4 stepper motor (forward and reverse according to the number of turns)
60行从零开始自己动手写FutureTask是什么体验?
攻防世界-PWN-new_easypwn
012年通过修补_sss_提高扩散模型效率
PHP operation mangoDb
化繁为简!阿里新产亿级流量系统设计核心原理高级笔记(终极版)
Ali's new launch: Microservices Assault Manual, all operations are written out in PDF
2022 Huashu Cup Mathematical Modeling Ideas Analysis and Exchange
阿里全新推出:微服务突击手册,把所有操作都写出来了PDF
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
第八章:activiti多用户任务分配
012_SSS_ Improving Diffusion Model Efficiency Through Patching
JS introduction to reverse the recycling business network of learning, simple encryption mobile phone number
第六章:activiti流程分流判断之排它网关和并行网关
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
百年北欧奢华家电品牌ASKO智能三温区酒柜臻献七夕,共品珍馐爱意
【MindSpore易点通机器人-01】你也许见过很多知识问答机器人,但这个有点不一样
静态链接和动态链接