当前位置:网站首页>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;
}边栏推荐
猜你喜欢

E-sports, convenience, efficiency, security, key words for OriginOS functions

three物体围绕一周呈球形排列

MySQL transactions

2022 Huashu Cup Mathematical Modeling Question A Optimization Design Ideas for Ring Oscillators Code Sharing

PCB布局必知必会:教你正确地布设运算放大器的电路板

Still looking for a network backup resources?Hurry up to collect the following network backup resource search artifact it is worth collecting!

产品太多了,如何实现一次登录多产品互通?

GPU-CUDA-图形渲染分析

Complete image segmentation efficiently based on MindSpore and realize Dice!

STM32+ULN2003驱动28BYJ4步进电机(根据圈数正转、反转)
随机推荐
Offensive World-PWN-new_easypwn
MySQL transactions
数据中台建设(十):数据安全管理
公众号如何运维?公众号运维专业团队
Chapter 5: Multithreaded Communication—wait and notify
SkiaSharp 之 WPF 自绘 投篮小游戏(案例版)
Dynamics 365Online PDF导出及打印
产品太多了,如何实现一次登录多产品互通?
第三章 : redis数据结构种类
Is digital transformation a business buy-in?
上位机开发C#语言:模拟STC串口助手接收单片机发送数据
创建一个 Dapp,为什么要选择波卡?
Opencv算术操作
STM32+ULN2003驱动28BYJ4步进电机(根据圈数正转、反转)
Go编译原理系列6(类型检查)
MySQL data view
数据可视化(二)
JS逆向入门学习之回收商网,手机号码简易加密解析
Chapter 4: activiti RuntimeService settings get and get process variables, and the difference from taskService, set process variables when starting and completing tasks [easy to understand]
How can project cost control help project success?