当前位置:网站首页>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;
}边栏推荐
- [Translation] Chaos Net + SkyWalking: Better observability for chaos engineering
- 用户考试分数大于单科科目平均分的查询
- 化繁为简!阿里新产亿级流量系统设计核心原理高级笔记(终极版)
- 产品太多了,如何实现一次登录多产品互通?
- Leetcode刷题——623. 在二叉树中增加一行
- 什么是 DevOps?看这一篇就够了!
- 告白数字化转型时代:麦聪软件以最简单的方式让企业把数据用起来
- 数据中台建设(十):数据安全管理
- How does the official account operate and maintain?Public account operation and maintenance professional team
- MySQL data view
猜你喜欢

JS逆向入门学习之回收商网,手机号码简易加密解析

Common operations of oracle under linux and daily accumulation of knowledge points (functions, timed tasks)

SQL Outer Join Intersection, Union, Difference Query

单片机:温度控制DS18B20

数据可视化(一)

Huawei's lightweight neural network architecture GhostNet has been upgraded again, and G-GhostNet (IJCV22) has shown its talents on the GPU

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

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

【OpenCV】-仿射变换

SQL外连接之交集、并集、差集查询
随机推荐
Chapter 5: Activiti process shunting judgment, judging to go to different task nodes
GPU-CUDA-图形渲染分析
产品太多了,如何实现一次登录多产品互通?
秘乐短视频挖矿系统开发详情
Login function and logout function (St. Regis Takeaway)
FPGA:开发环境Vivado的使用
High-quality DeFi application building guide to help developers enjoy DeFi Summer
js劫持数组push方法
How does the official account operate and maintain?Public account operation and maintenance professional team
SMB + SMB2: Accessing shares return an error after prolonged idle period
2022华数杯数学建模A题环形振荡器的优化设计思路思路代码分享
企业的数字化转型到底是否可以买来?
2022杭电多校 第6场 1008.Shinobu Loves Segment Tree 规律题
Create a Dapp, why choose Polkadot?
第八章:activiti多用户任务分配
19.3 restart the Oracle environment
【翻译】混沌网+SkyWalking:为混沌工程提供更好的可观察性
Dynamics 365Online PDF导出及打印
FPGA: Use of the development environment Vivado
[Android]如何使用RecycleView in Kotlin project