题目解读
新浪微博上有人发了某老板的作息时间表,表示其每天 4:30 就起床了。但立刻有眼尖的网友问:这时间表不完整啊,早上九点到下午一点干啥了?
本题就请你编写程序,检查任意一张时间表,找出其中没写出来的时间段。
AC CODE
//这里是引入了一些常用的头文件,和一些常规操作
//第一行是因为该死的编译器不让直接用scanf
#define _CRT_SECURE_NO_WARNINGS 1
#define _USE_MATH_DEFINES //启用M_PI的定义
#include<algorithm>
#include<iostream>
#include<sstream>
#include<cstring>
#include<iomanip>
#include<cstdio>
#include<cmath>
#include<string>
#include<vector>
#include<stack>
#include<queue>
#include<map>
#include<set>
#define MAX 0x3f3f3f3f
#define MIN -0x3f3f3f3f
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
string date[100100];
int main() {
int n;
cin >> n;
getchar();
for (int i = 0; i < n; i++) {
getline(cin, date[i]);
}
sort(date, date + n);
//第一个时间段看是否从0点开始
if(date[0].substr(0,8) != "00:00:00"){
cout << "00:00:00 - " << date[0].substr(0,8) << endl;
}
//下一行的开头必须是上一行的末尾,如果不是则输出上一行的末尾到这一行的开头
for(int i=1; i<n; i++){
if(date[i-1].substr(11,8) != date[i].substr(0,8)){
cout << date[i-1] .substr(11,8) << " - "<<date[i].substr(0,8) << endl;
}
}
//对最后一行数据进行特殊处理
if(date[n - 1].substr(11,8)!="23:59:59"){
cout << date[n-1].substr(11,8)<<" - 23:59:59" << endl;
}
return 0;
}
参考
B站up主一天五顿饭
🌻编写本篇文章目的是笔者想以输出的形式进行学习,顺便记录学习点滴🌻
🌹 如果本篇文章对你有帮助的话那就点个赞吧👍🌹
😇 本篇文章可能存在多处不足,如有修改意见,可以私信或者评论我哦 😇

3万+

被折叠的 条评论
为什么被折叠?



