AcWing
  • 首页
  • 活动
  • 题库
  • 竞赛
  • 应用
  • 更多
    • 题解
    • 分享
    • 商店
    • 问答
    • 吐槽
  • App
  • 登录/注册

AcWing 4473. 老板的作息表 --结构体    原题链接    中等

作者: 作者的头像   放弃考立刻推 ,  2023-03-19 23:54:20 ,  所有人可见 ,  阅读 31


0


#include <bits/stdc++.h>
using namespace std;
struct tim{
    int h1, m1, s1, h2, m2, s2;
}t[100000];
bool cmp(tim a, tim b)
{
    if ( a.h1 != b.h1 )
        return a.h1 < b.h1;
    else if ( a.m1 != b.m1 )
        return a.m1 < b.m1;
    else
        return a.s1 < b.s1;
};

int main(void)
{
    int n;
    cin >> n;
    for ( int i = 0; i < n; i ++ ) {
        scanf("%d:%d:%d - %d:%d:%d", &t[i].h1, &t[i].m1, &t[i].s1, &t[i].h2, &t[i].m2, &t[i].s2);
    }
    sort(t, t + n, cmp);
    if ( t[0].h1 != 0 || t[0].m1 != 0 || t[0].s1 != 0 ) {
        printf("00:00:00 - %02d:%02d:%02d\n", t[0].h1, t[0].m1, t[0].s1);
    }
    for ( int i = 0; i < n - 1; i ++ ) {
        if ( t[i].h2 != t[i+1].h1 || t[i].m2 != t[i+1].m1 || t[i].s2 != t[i+1].s1 )
            printf("%02d:%02d:%02d - %02d:%02d:%02d\n", t[i].h2, t[i].m2, t[i].s2, t[i+1].h1, t[i+1].m1, t[i+1].s1);
    }
    if ( t[n-1].h2 != 23 || t[n-1].m2 != 59 || t[n-1].s2 != 59 )
        printf("%02d:%02d:%02d - 23:59:59\n", t[n-1].h2, t[n-1].m2, t[n-1].s2);

    return 0;
}

0 评论

你确定删除吗?
1024
x

© 2018-2023 AcWing 版权所有  |  京ICP备17053197号-1
用户协议  |  隐私政策  |  常见问题  |  联系我们
AcWing
请输入登录信息
更多登录方式: 微信图标 qq图标
请输入绑定的邮箱地址
请输入注册信息