[PAT甲级]1006. Sign In and Sign Out (25)(找出机房开门锁门的人)

Excel COUNTIF函数精确统计全解析:从模糊匹配到精准计数 在数据处理与办公自动化领域,条件计数是数据分析的基础操作,其核心原理在于对特定范围内满足设定条件的单元格进行识别与汇总。Excel中的COUNTIF函数是实现这一功能的常用工具,它通过文本匹配逻辑与通配符机制来执行条件判断。然而,其默认的模糊匹配行为常导致统计结果偏离预期,这正是精确统计的技术价值所在——确保数据汇总的准确性与可靠性,直接影响业务报告、薪酬核算、销售分析等应用场景的决策质量。本文聚焦COUNTIF函数的精确匹配技巧,深入剖析通配符(如星号*和问号?)的转义使用(通过波浪号~),并针对大小写敏 阅读详情

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

题目大意:

  • 给出n个人的名字,签到时间和退出时间,找出最早来和最晚走的人的名字,即开门人和锁门人
  • n为正整数,一个人签到时间一定小于退出时间,不会有同时签到的情况

思路:

  • 刚开始我定义了结构体,自己电脑上运行没一点儿问题,提交显示编译错误,我实在找不出问题,就换了另一种方法
  • 将时间换算成秒进行比较,AC
  • 希望有人能看出问题的话,指导我一下,不胜感激

AC代码:

#include <iostream>
#include <cstdio>
#include <string>
using namespace std;
int main(){
    int m;
    scanf("%d", &m);
    string unlock_ID="",lock_ID="";//开门的人,锁门的人
    int unlock_time = 86400;//开门时间
    int lock_time = 0;//锁门时间
    for(int i=0; i<m; i++){
        string ID_number;
        cin >> ID_number;
        int h1,h2,m1,m2,s1,s2;
        scanf("%02d:%02d:%02d %02d:%02d:%02d", &h1, &m1, &s1, &h2, &m2, &s2);
        int timeIn = h1*3600+m1*60+s1;//转化成秒
        int timeOut = h2*3600+m2*60+s2;
        if(timeIn <= unlock_time){//如果此人来得更早,此人开门,更新开门时间
            unlock_ID = ID_number;
            unlock_time = timeIn;
        }
        if(timeOut >= lock_time){//如果此人走得更晚,此人锁门,更新锁门时间
            lock_ID = ID_number;
            lock_time = timeOut;
        }
    }
    cout << unlock_ID << " " << lock_ID;
    return 0;
}

代码2:(自己电脑运行没问题,但是提交显示编译错误)

#include <iostream>
#include <string>
#include <cstdio>
using namespace std;
struct time{
    int hh;
    int mm;
    int ss;
};
bool isEarlier(time aa, time bb){
    if(aa.hh<=bb.hh || (aa.hh==bb.hh&&aa.mm<=bb.mm) || (aa.hh==bb.hh&&aa.mm==bb.mm&&aa.ss<=bb.ss))
        return true;
    return false;
}
int main()
{
    int m;
    scanf("%d", &m);
    string unlock_ID="",lock_ID="";//开门的人,锁门的人
    time unlock_time,lock_time;//开门时间,锁门时间
    unlock_time.hh = 23;
    unlock_time.mm = 59;
    unlock_time.ss = 59;
    lock_time.hh = 0;
    lock_time.mm = 0;
    lock_time.ss = 0;
    for(int i=0; i<m; i++){
        string ID_number;
        cin >> ID_number;
        time a; time b;
        scanf("%02d:%02d:%02d %02d:%02d:%02d", &a.hh, &a.mm, &a.ss, &b.hh, &b.mm, &b.ss);
        if(isEarlier(a, unlock_time)){//如果此人来得更早,此人开门,更新开门时间
            unlock_ID = ID_number;
            unlock_time = a;
        }
        if(isEarlier(lock_time, b)){//如果此人走得更晚,此人锁门,更新锁门时间
            lock_ID = ID_number;
            lock_time = b;
        }
    }
    cout << unlock_ID << " " << lock_ID;
    return 0;
}
【用unity实现100个游戏之2】复刻实现经典2d平台跳跃游戏《蔚蓝 Celeste》(附工程源码) 蔚蓝》是一款备受好评的独立游戏,由游戏开发工作室开发并由发行。这款游戏于2016年首次发布,并在玩家和评论界收获了广泛赞誉。蔚蓝以其独特的艺术风格和引人入胜的故事而著称。游戏以深海为背景,玩家将扮演一个能够探索水下世界的神秘生物。游戏通过惊人的视觉表现和动态的海洋生态系统为玩家带来了令人难忘的游戏体验。无论是广阔的水下景观还是充满生机的海洋生物,蔚蓝都让玩家感受到深海的神秘和美丽。蔚蓝在玩法上注重探索和解谜。玩家可以在海底环境中自由游动,发现隐藏的地点和秘密,与各种生物互动,并解决环境谜题以继续前进。 阅读详情

相关推荐

搭建PX4开发系统(Ubuntu 22.04)

本文是《从零开始学 PX4 无人机开发》系列第二篇,适合开发者在 Ubuntu 系统下快速搭建 PX4 编译与仿真环境,支持 QGroundControl、Gazebo、MAVSDK 等完整工具链。

qq_15856721的博客 4219

PAT甲级1006 Sign In and Sign Out

编程题 - PAT (Advanced Level) Practice (pintia.cn)https://pintia.cn/problem-sets/994805342720868352/exam/problems/type/7

song0789的博客 925

基于Arduino 的 FM 调频收音机

这是一个基于 Arduino 的开源的收音机项目,它具备一台标准收音机的全部功能,从控制部分到外壳都可以自己 DIY。在项目中,我们将介绍让 FM 收音机调谐器的 RDA5807 模块与 I2C 协议进行通信的方法,整个过程只需要两根线就可以与 IC 通信,接线非常简单。3D 打印的外壳也非常简洁。总之,是个非常简单和实用的项目,来试试吧!

ByteBox的博客 1643

「PAT甲级真题解析」Advanced Level 1006 Sign In and Sign Out

1. 题目给出一组学生进入机房的进入时间和离开时间, 要求找出最早进入机房开门的人以及最晚离开机房锁门的人. 到这里我们可以看出题目的重点在于查找, 而查找会涉及到数据的存储, 如果存储数据以及在储存的数据中进行查找是我们要考虑的核心。 2. 我们可以存储所有的进入时间和对应的学生ID, 然后比较出最早的进入时间。但我们在乙级的题目练习中多次提到, 数据存储是为了使用, 在这种情况下, 进入时间在进行一次比较之后就不会再用到了, 所以可以不需要存储全部进入时间, 而是直接存储当前最早进入时间然后不断更新。

过美好生活,做高效程序员 5419

Tlsr8258开发-程序烧写

开源一小步,进步一大步

自学嵌入式 1778

C#实战:如何用TSCLIB.dll实现TSC打印机的状态监控与异常处理(附完整代码)

本文详细介绍了如何利用C#和TSCLIB.dll构建企业级TSC打印机状态监控与智能异常处理系统。通过解析十六进制状态码、设计高可靠性的轮询引擎以及实现事件驱动的报警机制,开发者可以打造一个稳定、可观测的打印服务,有效保障物流仓储、生产制造等高频打印场景的业务连续性。

weixin_29227585的博客 64

PAT甲级(Advanced Level) Practice 1006 Sign In and Sign Out

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 loc

2301_78006009的博客 563

OpenClaw 完整命令文档(2026.3.13 最新版)

本文档为OpenClaw 2026.3.13通用版使用指南,包含核心命令大全。主要内容包括:1)基础安装/升级/卸载命令;2)ClawHub扩展安装命令(支持飞书/钉钉/企微等平台连接);3)Skills技能安装命令(实现聊天/搜索/记忆等功能);4)飞书机器人授权与配对命令;5)启动运行与配置检查命令;6)工作区与记忆管理命令;7)插件安全设置命令;8)调试日志命令;9)飞书机器人一键部署简化流程。文档特别强调飞书机器人部署需feishu扩展+对应技能+用户授权的完整配置,所有命令均需在终端执行,安装后需

MKliudan的专栏 1294

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

PAT甲级 1006 Sign In and Sign Out(25分)题目Input Specification:Output Specification:Sample Input:Sample Output:题解题目大意非正规思路挫挫的代码絮絮叨叨参考博客 题目 At the beginning of every day, the first person who signs in the computer room will unlock the door, and the last one who

weixin_44585441的博客 193

当迁移学习遇见室内定位:基于UJIIndoorLoc的跨场景适配实践

本文探讨了迁移学习在跨建筑室内定位中的应用,重点解析了UJIIndoorLoc数据集的特性及其在解决设备差异和环境变化中的关键作用。通过特征工程、迁移学习策略和小样本微调技术,显著提升了定位模型的跨场景适配能力,为实际部署提供了有效解决方案。

weixin_29038155的博客 394

RT-DETR-R18 的轻量化 Trick:剪枝与量化在模型中的应用

RT-DETR-R18轻量化技术通过结构化剪枝、混合精度量化和知识蒸馏的组合优化,实现了显著模型压缩效果。摘要如下: RT-DETR-R18模型通过创新轻量化技术组合,在保持46.2% mAP精度的前提下,将模型大小压缩至2.1MB(压缩率78%),计算量降至3.2 GFLOPs(减少78.2%),实现移动端28ms实时推理(加速37.8%)。核心技术包括:1)渐进式结构化剪枝系统,通过L1范数重要性评估和动态剪枝调度;2)混合精度量化策略,对关键层保留FP16精度;3)教师-学生知识蒸馏框架保持模型表达能

走向CTO的路上... 1194

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

1006Sign 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 reco...

Dexter 269

android 蓝牙通讯demo

android 下蓝牙通讯demo,实现了发现蓝牙,使能蓝牙,通过蓝牙发送消息。

【PAT甲级 - C++题解】1006 Sign In and Sign Out

📣专栏定位:为想考甲级PAT的小伙伴整理常考算法题解,祝大家都能取得满分!

Newin2020的博客 531

VC中sqlite的使用

在VC中对sqlite的使用,实现数据库大批数据的快速插入,读取数据库中的数据在ListCtrl中显示

大中型超市收银系统(可直接运行)

光步前台收银系统系统功能:商品销售、商品退货、挂单、收银员权限、会员销售、单品取消、整单取消、商品查询、脱机销售、脱机数据上传,基本资料下载,开钱箱、小票打印、收款结算,支持多币种付款方式(现金、储值卡、礼券、微信等),支持多种促销。运行环境:.net 4.0登陆信息用户名:1001 密码:123456内置商品信息,商品编码可输入00001000 - 00010000,测试效果相关功能键F5 结算 F9挂单 F11商品查询 F8退货 Insert单品取消 Del整单取消 F12开钱箱F2 会员 Ctrl+Z退出系统 Home 锁屏 相关源码待公开

【PAT甲级】 1006 Sign In and Sign Out

map的运用

lemon1219的博客 380

【PAT】PAT A-1006 Sign In and Sign Out【简单模拟】

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...

elegant coder 1435

C++ Pat甲级1006 Sign In and Sign Out (25 分)(字符串strcmp , strcpy)

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 reco...

Scarlett 292

PAT-Apat甲级题1006(python和c++实现)

1006 Sign In and Sign Out 作者 CHEN, Yue 单位 浙江大学 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 s

qq3342560494的博客 848

PAT 甲级题目讲解:1006《Sign In and Sign Out》

本题需判断给定人员中的最早签到者(解锁者)与最晚签出者(锁门者)。解题关键是将时间统一转换为“当日秒数”以方便比较,思路简洁高效,适合练习时间格式解析与比较最值。

qq_35624947的博客 379

1006. Sign In and Sign Out (25)-PAT甲级真题

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 r

柳婼 の blog 2315

PAT习题:Sign In and Sign Out (25)

小编准备考PAT甲级的证,因此开始刷题中。将刷过的题及自己所编的代码进行整理分享。 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 ...

qq_35864862的博客 278

PAT甲级-1006 Sign In and Sign Out

1006Sign 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 reco...

得未曾有 心净踊跃 202

pat 甲级 1006 sign in and sign out(C/C++)

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 th

蔡尼玛的博客 133

PAT甲级之路--1006 1006 Sign In and Sign Out

题目重述: 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...

liuchunyv711的博客 221

pat 甲级 A1006 Sign In and Sign Out (25分)

题目链接: https://pintia.cn/problem-sets/994805342720868352/problems/994805516654460928 题目分析: 根据一天中多人到达机房时间和离开时间,给出开门以及锁门人的ID。显然可以对到达时间,以及离开时间进行排序,最早的时间即为第一个人到达时间,最晚时间即为最后一个人离开时间。但是这容易超时。转换思路,可以想...

dutmathjc的博客 166

【PAT(甲级)】1006 Sign In and Sign Out

【PAT(甲级)】1006 Sign In and Sign Out 易错点,思路解答,代码里附有详细的说明

weixin_55202895的博客 458

PAT甲级 1006 Sign In and Sign Out(JAVA)

PAT甲级 1006 Sign In and Sign Out

paradipose的博客 188

A1006-PAT甲级JAVA题解 Sign In and Sign Out

核心思路:找到最早进入的员工和最晚离开的员工,无需记录时间,可以直接用long比对,java可ac不超时。

qq_49695680的博客 442
上一篇: [PAT甲级]1005. Spell It Right (20)(求数字各个位上的和,英文输出)
下一篇: [PAT甲级]1007. Maximum Subsequence Sum(求连续最大子序列和)
whl_program
博客等级 码龄11年 101粉丝 279原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

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

抵扣说明:

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

余额充值