PAT甲级 1006. Sign In and Sign Out(25分)

简介: PAT甲级 1006. Sign In and Sign Out(25分)

1006. Sign In and Sign Out(25分)


At the beginning of every day, the first person who signs in the computer room will unlock the door, and the last one who signs out will lock the door. Given the records of signing in’s and out’s, you are supposed to find the ones who have unlocked and locked the door on that day.


Input Specification:

Each input file contains one test case. Each case contains the records for one day. The case starts with a positive integer M, which is the total number of records, followed by M lines, each in the format:

ID_number Sign_in_time Sign_out_time

where times are given in the format HH:MM:SS, and ID_number is a string with no more than 15 characters.


Output Specification:

For each test case, output in one line the ID numbers of the persons who have unlocked and locked the door on that day. The two ID numbers must be separated by one space.


Note: It is guaranteed that the records are consistent. That is, the sign in time must be earlier than the sign out time for each person, and there are no two persons sign in or out at the same moment.


Sample Input:

3
CS301111 15:30:28 17:00:10
SC3021234 08:00:00 11:25:25
CS301133 21:45:00 21:58:40
结尾无空行


Sample Output:

SC3021234 CS301133
结尾无空行
#include <iostream>
using namespace std;
struct Time
{
    int hour;
    int minute;
    int second;
};
struct Person
{
    string id;
    Time in_time;
    Time out_time;
};
int main()
{
    int M;
    cin >> M;
    Person p;
    int early_in_time = 1e9, late_out_time = 0;
    string early_person, late_person;
    for (int i = 0; i < M; i++)
    {
        cin >> p.id;
        scanf("%d:%d:%d", &p.in_time.hour, &p.in_time.minute, &p.in_time.second);
        scanf("%d:%d:%d", &p.out_time.hour, &p.out_time.minute, &p.out_time.second);
        int intime = (p.in_time.hour * 60 + p.in_time.minute) * 60 + p.in_time.second;
        int outtime = (p.out_time.hour * 60 + p.out_time.minute) * 60 + p.out_time.second;
        if (intime < early_in_time)
        {
            early_in_time = intime;
            early_person = p.id;
        }
        if (outtime > late_out_time)
        {
            late_out_time = outtime;
            late_person = p.id;
        }
    }
    cout << early_person << " " << late_person;
    return 0;
}

很简单的题,但我的代码写的特别烂。完全没有必要写这么复杂,还结构里嵌套了结构,要搞清楚一点,求的其实是时间戳,何况是同一天的,只需要考虑一共占用了多少秒,再依次比较求出最值即可。感觉陷入了一种思维惯性,不仅仅要考虑优化算法,写法的优化也是不可缺少的。

目录
相关文章
|
小程序 开发者 安全
福利!支付宝小程序开发必备的7款开源DEMO
相比于APP,小程序已经大大降低了开发者们的学习和开发的门槛。而如何进一步提高小程序开发者的学习和开发效率,一直是支付宝小程序团队非常重视的课题。对于开发者而言, 文档可以提供基础的引导,而针对性的、基于常见场景的DEMO则更为直观清晰易懂,可以大大节约上手的成本。
8163 0
福利!支付宝小程序开发必备的7款开源DEMO
|
4月前
|
传感器 数据采集 数据可视化
基于STM32的智能家居控制系统设计
基于STM32的智能家居控制系统设计
689 10
|
4月前
|
机器学习/深度学习 人工智能 算法
脑肿瘤识别目标检测数据集(1200张图片已划分、已标注)| AI训练适用于目标检测任务
本数据集含1200张高质量脑部MRI影像,已精准标注“阴性/阳性”二分类标签,并划分训练集与验证集,适用于YOLO、ResNet等模型的脑肿瘤自动识别与辅助诊断任务,结构规范、即取即用。
|
4月前
|
机器学习/深度学习 传感器 数据采集
告别死记硬背,这篇机器学习“黑话”指南让你秒变内行
本 glossary 以工业制造为隐喻,系统梳理机器学习全链路核心概念:从数据预处理(特征工程、归一化、降维等)、主流算法(SVM、CNN、Transformer等),到训练优化(损失函数、反向传播、正则化)、模型评估(混淆矩阵、F1、AUC)及工程部署(MLOps、边缘推理)。共52个术语,兼顾准确性与可理解性,助力快速掌握ML知识体系。(239字)
545 4
|
7月前
|
人工智能 DataWorks
Forrester Wave™: AI Platforms in China, Q4 2025发布,阿里云入选领导者
Forrester 发布《Forrester Wave: AI Platforms in China, Q4 2025》,阿里云位列领导者类别,在产品类别排名第二,战略类别排名第一。其中在25项评估细项中有19项拿到5分的满分评价,是获得满分(5分)评分数量最多的两家厂商之一。
|
4月前
|
机器学习/深度学习 人工智能 监控
猪的危险行为数据集(5000+高清标注)| YOLO实战 智慧养殖与异常行为预警
本数据集开源5000+高清标注样本,精准覆盖猪只攻击、咬耳朵、咬尾巴三类危险行为,标注准确率≥98%,按7:1.5:1.5划分训练/验证/测试集,YOLO格式,兼容v5/v8/v11,支持智慧养殖实时预警与异常行为监测。
|
4月前
|
机器学习/深度学习 人工智能 算法
孪生素数分布的大规模计算实验:分段筛实现与经验统计分析
孪生素数猜想断言存在无穷多对形如 (p,p+2)(p,p+2) 的素数,但该猜想至今仍未解决。Hardy–Littlewood 的第一猜想给出了孪生素数计数函数的经典启发式渐近公式,而张益唐、Maynard 与 Polymath8 的工作则证明了存在无穷多对素数,其间隔有统一上界,但这一上界尚未降至 2 [1–3]。
556 13
|
4月前
|
人工智能 自然语言处理 安全
用了几个月的心得,教你把AI开源知识库用透
在知识管理领域混迹多年,尝试过各类系统和助手,这次总结一下经验教训。AI开源知识库系统的核心价值,在于务实解决实际问题,而非堆砌花哨功能,能有效改善知识创作、检索与协作中的低效困境。下文结合我的实操经验,详细分享该系统的部署方法、核心功能用法、落地案例及避坑技巧,全程聚焦干货,不冗余、不浮夸。
|
5月前
|
人工智能 数据可视化 文件存储
MIT开源 首款P2P-AIBridge工具 OoderNexus 发布
Nexus是基于OoderAgent V0.6.5的可视化开发套件,旨在降低P2P AI通信门槛。它提供设备管理(路由器/NAS/智能家居)、SkillFlow编排、场景配置等示例界面,让开发者快速构建SuperAgent分发系统,实现AI能力的直观调用与扩展。(239字)
MIT开源 首款P2P-AIBridge工具  OoderNexus 发布
|
5月前
|
人工智能 自然语言处理 运维
企业如何应用智能客服(2026年2月最新)
截至2026年,全球智能客服市场达487亿美元(CAGR 23.1%),中国大型企业部署率超78%。大模型驱动下,准确率达92.5%,响应仅0.8秒,降本超30%。合规性成关键,瓴羊Quick Service以“大模型+小模型+业务流”架构,实现场景化、可运营、可度量的智能服务升级。(239字)