L2-042 老板的作息表 #字符串模拟


题目解读

新浪微博上有人发了某老板的作息时间表,表示其每天 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主一天五顿饭


🌻编写本篇文章目的是笔者想以输出的形式进行学习,顺便记录学习点滴🌻

🌹 如果本篇文章对你有帮助的话那就点个赞吧👍🌹

😇 本篇文章可能存在多处不足,如有修改意见,可以私信或者评论我哦 😇


在这里插入图片描述

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值