【GPLT 二阶题目集】L2-042 老板的作息表

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

//先将作息表中各时间段按照起始时间进行升序排序
//再判断两个时间段之间是否有其它时间段,有就输出
//首尾时间段另外考虑,作息表只有一个时间段另外考虑
#include <iostream>
#include <map>
#include <vector>
using namespace std;

class Time {
public:
    int hh;
    int mm;
    int ss;
    bool operator==(Time& t)
    {
        if (this->hh == t.hh && this->mm == t.mm && this->ss == t.ss)
            return true;
        else
            return false;
    }
    void print()
    {
        printf("%02d:%02d:%02d", this->hh, this->mm, this->ss);
    }
};

class cmp {
public:
    bool operator()(Time a, Time b) const {
        if (a.hh != b.hh)
            return a.hh < b.hh;
        else if (a.mm != b.mm)
            return a.mm < b.mm;
        else
            return a.ss < b.ss;
    }
};

int main()
{
    int n; cin >> n;
    map<Time, Time, cmp> time_temp;

    Time t1, t2;
    while (n--) {
        scanf("%d:%d:%d - %d:%d:%d", &t1.hh, &t1.mm, &t1.ss, &t2.hh, &t2.mm, &t2.ss);
        time_temp.insert(make_pair(t1, t2));
    }

    vector< pair<Time, Time> > time(time_temp.begin(), time_temp.end());
    if (time[0].first.hh != 0 || time[0].first.mm != 0 || time[0].first.ss != 0)
    { //作息表是否从00:00:00开始
        cout << "00:00:00 - ";
        time[0].first.print();
        cout << endl;
    }
    if (time.size() > 1) { //作息表内容至少要有两条(判断二者间是否有时间差)
        for (int i = 0; i < time.size() - 1; i++) {
            if (!(time[i].second == time[i + 1].first)) {
                time[i].second.print();
                cout << " - ";
                time[i + 1].first.print();
                cout << endl;
            }
        }
    }
    int temp = time.size() - 1;
    if (!(time[temp].second.hh == 23 && time[temp].second.mm == 59 && time[temp].second.ss == 59))
    { //作息表是不是于23:59:59结束
        time[temp].second.print();
        cout << " - 23:59:59" << endl;
    }
    return 0;
}

 注意事项:

如有问题,欢迎提出。

  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
根据提供的代码和输入输出样例,这段代码是一个解决L2-009 抢红包问题的程序。该程序接受一个整数n作为输入,示参与抢红包的人数。然后依次输入每个人的编号和抢到的红包金额。程序会根据收入金额从高到低的递减顺序输出每个人的编号和收入金额(以元为单位,输出小数点后2位)。如果收入金额有并列,则按抢到红包的个数递减输出;如果还有并列,则按个人编号递增输出。 对于给定的输入样例10 3 2 22 10 58 8 125 5 1 345 3 211 5 233 7 13 8 101 1 7 8800 2 1 1000 2 1000 2 4 250 10 320 6 5 11 9 22 8 33 7 44 10 55 4 2 1 3 8800 2 1 23 2 123 1 8 250 4 2 121 4 516 7 112 9 10,程序的输出样例应为1 0.00 2 0.00 3 0.00 4 0.00 5 0.00 6 0.00 7 0.00 8 0.00 9 0.00 10 0.00。 请注意,这段代码使用了C++的标准库函数和算法,包括iostream、algorithm和using namespace std。它还定义了一个Person类,用于存储每个人的编号、收入金额和抢到红包的个数。程序通过对Person对象数组进行排序,按照要求输出每个人的编号和收入金额。 希望这个解释对你有帮助! #### 引用[.reference_title] - *1* *2* *3* [【GPLT 二阶题目L2-009 抢红包](https://blog.csdn.net/DeskOneRice/article/details/128783061)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v91^insert_down1,239^v3^insert_chatgpt"}} ] [.reference_item] [ .reference_list ]

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

花辞树dor

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值