L2-042 老板的作息表 超级无敌简单的方法solve

题目传送门
在这里插入图片描述
这题初看我想着全部转化成秒然后再差分把、每一个数标记一下,再遍历重找一下写。但是这样显然比较麻烦,又想到之前写的有关地址的题,诶我直接把他们变成一个6位数然后sort一下不就完美解决了?代码非常简单, 应该每一步都一眼看出我想干嘛,就不写注释了绝对不是因为懒得写注释 qwq

#include <bits/stdc++.h>
#define sc(x) scanf("%d", &x)
#define pf(x) printf("%d", x)
#define pfn(x) printf("%d\n", x)
using namespace std;
const int N = 250000;
vector<int> v, ans;
string change(int x)
{
    int s = x % 100;
    x /= 100;
    int m = x % 100;
    x /= 100;
    int h = x % 100;
    string res = "";
    if (h < 10)
        res += "0", res += to_string(h);
    else
        res += to_string(h);
    res += ":";
    if (m < 10)
        res += "0", res += to_string(m);
    else
        res += to_string(m);
    res += ":";
    if (s < 10)
        res += "0", res += to_string(s);
    else
        res += to_string(s);
    return res;
}
int main()
{
    int n;
    sc(n);
    while (n--)
    {
        int x, y, z, x2, y2, z2;
        scanf("%d:%d:%d - %d:%d:%d", &x, &y, &z, &x2, &y2, &z2);
        getchar();
        int tmp = x * 10000 + y * 100 + z, tmp1 = x2 * 10000 + y2 * 100 + z2;
        v.push_back(tmp);
        v.push_back(tmp1);
    }
    sort(v.begin(), v.end());
    if (v[0] != 0)
        ans.push_back(0), ans.push_back(v[0]);
    for (int i = 1; i < v.size() - 1; i+=2)
    {
        if (v[i] != v[i + 1])
        {
            ans.push_back(v[i]);
            ans.push_back(v[i + 1]);
        }
    }
    if (v.back() != 235959)
    {
        ans.push_back(v.back());
        ans.push_back(235959);
    }
    for (int i = 0; i < ans.size() - 1; i += 2)
    {
        string x1 = change(ans[i]), x2 = change(ans[i + 1]);
        printf("%s - %s\n", x1.c_str(), x2.c_str());
    }
    return 0;
}
  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值