当前位置:网站首页>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;
}
边栏推荐
- R语言使用yardstick包的pr_curve函数评估多分类(Multiclass)模型的性能、查看模型在多分类每个分类上的ROC曲线(precision(精准率),R代表的是recall(召回率)
- 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
- How can project cost control help project success?
- Score interview (1)----related to business
- 第九章:activit内置用户组设计与组任务分配和IdentityService接口的使用
- 导火索:OAuth 2.0四种授权登录方式必读
- 数据可视化(二)
- linux下oracle常见操作以及日常积累知识点(函数、定时任务)
- 字节一面:TCP 和 UDP 可以使用同一个端口吗?
- Header file search rules when compiling with GCC
猜你喜欢
PCB布局必知必会:教你正确地布设运算放大器的电路板
Opencv算术操作
In-depth understanding of timeout settings for Istio traffic management
STM32+ULN2003驱动28BYJ4步进电机(根据圈数正转、反转)
Opencv图像缩放和平移
What is SPL?
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
【OpenCV】-仿射变换
Meteorological data processing example - matlab string cutting matching and R language date matching (data splicing)
华为轻量级神经网络架构GhostNet再升级,GPU上大显身手的G-GhostNet(IJCV22)
随机推荐
STM32+ULN2003 drives 28BYJ4 stepper motor (forward and reverse according to the number of turns)
力扣(LeetCode)216. 组合总和 III(2022.08.04)
MySQL transactions
【翻译】混沌网+SkyWalking:为混沌工程提供更好的可观察性
What is SPL?
Where is your most secretive personality?
RT-Thread记录(一、RT-Thread 版本、RT-Thread Studio开发环境 及 配合CubeMX开发快速上手)
2022杭电多校 第6场 1008.Shinobu Loves Segment Tree 规律题
GPU-CUDA-图形渲染分析
The query that the user's test score is greater than the average score of a single subject
【MindSpore易点通机器人-01】你也许见过很多知识问答机器人,但这个有点不一样
Complete image segmentation efficiently based on MindSpore and realize Dice!
Jenkins manual (2) - software configuration
The founder of the DFINITY Foundation talks about the ups and downs of the bear market, and where should DeFi projects go?
七夕来袭!还要做CDH数据迁移怎么办?来看看DistCp
Leetcode刷题——623. 在二叉树中增加一行
教你本地编译运行一个IDEA插件,在IDEA里聊天、下棋、斗地主!
数分面试(一)----与业务相关
RT - Thread record (a, RT, RT Thread version - Thread Studio development environment and cooperate CubeMX quick-and-dirty)
FPGA:基础入门LED灯闪烁