L2-2 老板的作息表(2023天梯赛模拟赛)
新浪微博上有人发了某老板的作息时间表,表示其每天 4:30 就起床了。但立刻有眼尖的网友问:这时间表不完整啊,早上九点到下午一点干啥了?
本题就请你编写程序,检查任意一张时间表,找出其中没写出来的时间段。
#include<bits/stdc++.h>
using namespace std;
struct node
{
string one,two;
}s[100001];
bool cmp(node a,node b)
{
return a.one < b.one;
}
int main()
{
int n;
cin>>n;
string c;
for(int i=0; i<n; i++)
{
cin >> s[i].one >> c >> s[i].two;
}
sort(s, s + n, cmp);//将作息时间从小到大排序
//处理时间边界
string x="00:00:00";
string y="23:59:59";
for(int i=0; i<n; i++)
{
if(x == s[i].one)//判断作息表是否从00:00:00开始
x=s[i].two;
else
{
cout << x << " - " << s[i].one << endl;
x=s[i].two;
}
}
if(x!=y)//判断作息表是否到23:59:59结束
cout<<x<<" - "<<y;
return 0;
}
利用结构体存储,再读入时间的ascll码的大小进行排序得到从早到晚的作息表
但是要注意00:00:00和23:59:59这两个边界的处理。