码农知识堂 - 1000bd
  •   Python
  •   PHP
  •   JS/TS
  •   JAVA
  •   C/C++
  •   C#
  •   GO
  •   Kotlin
  •   Swift
  • PAT 1006 Sign In and Sign out


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

    1. 3
    2. CS301111 15:30:28 17:00:10
    3. SC3021234 08:00:00 11:25:25
    4. CS301133 21:45:00 21:58:40

    Sample Output:

    SC3021234 CS301133

    题目大意:在记录中查找开门的人和关门的人,也就是第一个进门最早的人和最晚出门的人

    思路:这题还是比较简单的,稍微需要思考的是时间 HH:MM:SS 这样的,怎么表示时间和比较时间的大小就是这道题目的关键,可以直接将时间转化成数字,比如:21:31:23 -> 213123 这样的数字来存储,比较大小也方便(多刷题还是有用的!!!)

     代码:

    1. #include
    2. using namespace std;
    3. int main(){
    4. int n,e=0,l=0;//e表是开门人的下标,l表示锁门人的下标
    5. cin >> n;
    6. string name[n];
    7. int in[n],out[n];
    8. int h,m,s,t;
    9. for(int i=0;i
    10. cin >> name[i];
    11. scanf("%d:%d:%d",&h,&m,&s);
    12. t=h*10000+m*100+s;
    13. in[i]=t;
    14. e=in[e]
    15. scanf("%d:%d:%d",&h,&m,&s);
    16. t=h*10000+m*100+s;
    17. out[i]=t;
    18. l=out[l]>out[i]?l:i;
    19. }
    20. cout << name[e] << ' ' << name[l];
    21. return 0;
    22. }

    大佬的代码也很好,借鉴借鉴:

    1. #include
    2. #include
    3. using namespace std;
    4. int main() {
    5. int n, minn = INT_MAX, maxn = INT_MIN;
    6. scanf("%d", &n);
    7. string unlocked, locked;
    8. for(int i = 0; i < n; i++) {
    9. string t;
    10. cin >> t;
    11. int h1, m1, s1, h2, m2, s2;
    12. scanf("%d:%d:%d %d:%d:%d", &h1, &m1, &s1, &h2, &m2, &s2);
    13. int tempIn = h1 * 3600 + m1 * 60 + s1;
    14. int tempOut = h2 * 3600 + m2 * 60 + s2;
    15. if (tempIn < minn) {
    16. minn = tempIn;
    17. unlocked = t;
    18. }
    19. if (tempOut > maxn) {
    20. maxn = tempOut;
    21. locked = t;
    22. }
    23. }
    24. cout << unlocked << " " << locked;
    25. return 0;
    26. }

    好好学习,天天向上!

    我要考研!

  • 相关阅读:
    【Java】List、Set、数据结构、Collections
    CentOS7和CentOS8 Asterisk 20.0.0 简单图形化界面9--对接鼎兴FXO网关落地
    记一次springboot项目结合arthas排查ClassNotFoundException问题
    python毕业设计作品基于django框架 多用户商城平台系统毕设成品(6)开题答辩PPT
    【C++】class的设计与使用(十)重载iostream运算符
    【数值分析】用幂法计算矩阵的主特征值和对应的特征向量(附matlab代码)
    Spring Cloud全家桶(上)【Nacos、OpenFeign、LoadBalancer、GateWay、金丝雀灰色发布】
    数据管理能力成熟度评估模型是什么
    关于在本地启动跨域非nodejs的前后端分离项目
    分析类的初始化
  • 原文地址:https://blog.csdn.net/weixin_50679551/article/details/126608063
  • 最新文章
  • 【JVM】编译执行与解释执行的区别是什么?JVM 使用哪种方式?
    用 Hashids 优雅解决 C 端自增 ID 暴露问题
    V8引擎 精品漫游指南--Ignition篇(上) 指令 栈帧 槽位 调用约定 内存布局 基础内容
    LLVM Pass快速入门(四):代码插桩
    milkup:桌面端 markdown AI续写和即时渲染
    基于项目工程构建SBOM(软件物料清单)的研究
    鸿蒙应用开发UI基础第二节:鸿蒙应用程序框架核心解析与实操
    .NET 中如何快速实现 List 集合去重?
    扣子Coze实战:从0到1打造抖音+小红书热点监控智能体
    浅谈数据访问层
  • 热门文章
  • 十款代码表白小特效 一个比一个浪漫 赶紧收藏起来吧!!!
    奉劝各位学弟学妹们,该打造你的技术影响力了!
    五年了,我在 CSDN 的两个一百万。
    Java俄罗斯方块,老程序员花了一个周末,连接中学年代!
    面试官都震惊,你这网络基础可以啊!
    你真的会用百度吗?我不信 — 那些不为人知的搜索引擎语法
    心情不好的时候,用 Python 画棵樱花树送给自己吧
    通宵一晚做出来的一款类似CS的第一人称射击游戏Demo!原来做游戏也不是很难,连憨憨学妹都学会了!
    13 万字 C 语言从入门到精通保姆级教程2021 年版
    10行代码集2000张美女图,Python爬虫120例,再上征途
小工具 小游戏
Copyright © 2022 侵权请联系2656653265@qq.com    京ICP备2022015340号-1

京公网安备 11010502049817号