前言

传送门

正文

题目描述

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

解题思路:

题意就是找到最早签到和最晚签离的人,首先可用一个结构体person来存储姓名和小时,分钟,秒。设置结构体型变量start,end来分别存储最早签到和最晚签离的人的信息,而temp则存储每次读入的人的信息。这里需要注意temp可以先读入签到时间,与start比较完后,再读入签离时间,与end比较。最终start就是最早签到的人的信息,end就是最晚签离的人的信息。
(后面很多题都有用到temp临时变量来存储读入的每项数据,然后再通过compare来不断更新题目最终结果要求的数据项)

参考题解:

#include<cstdio>
struct person{char name[16];int hh,mm,ss;
}start,end,temp;
\\a的时间若比b的时间晚则返回true
bool cmp(person a,person b){if(a.hh!=b.hh)return a.hh>b.hh;if(a.mm!=b.mm)return a.mm>b.mm;return a.ss>b.ss;
}
void init(){end.hh=0;end.mm=0;end.ss=0;\\设置初始签离时间为最早start.hh=23;start.mm=59;start.ss=59;\\设置初始签到时间为最晚
}
int main(){init();int n;scanf("%d",&n);while(n--){scanf("%s %d:%d:%d",temp.name,&temp.hh,&temp.mm,&temp.ss);if(!cmp(temp,start))start=temp;scanf("%d:%d:%d",&temp.hh,&temp.mm,&temp.ss);if(cmp(temp,end))end=temp;}printf("%s %s\n",start.name,end.name);return 0;
}

后记

初次尝试GuiMiner挖矿

PAT A1006 Sign In and Sign Out相关推荐

  1. PAT甲级1006 Sign In and Sign Out:[C++题解]字符串处理

    文章目录 题目分析 题目链接 题目分析 读入三个字符串. 需要记录最早开门的人的id和时间,最晚离开的人的id和时间. 本题的简单之处在于 时间的位数都相同,比如 10点和01点.因此这样的时间大小比 ...

  2. [Java] 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 com ...

  3. 【PAT甲】1006 Sign In and Sign Out (25分)循环模拟

    problem 1006 Sign In and Sign Out (25分) At the beginning of every day, the first person who signs in ...

  4. Sign In and Sign Out

    1006. Sign In and Sign Out (25) 时间限制 400 ms 内存限制 65536 kB 代码长度限制 16000 B 判题程序 Standard 作者 CHEN, Yue ...

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

  6. [sign in和sign up哪个是注册?哪个是登入?]

    sign in和sign up的意思: 如果是网站的话sign up是注册,sign in是登录的意思,另外,sign out退出

  7. (翻译)‘Sign Up’ 和‘Sign In’按钮让用户混淆的原因

      你能多快看出"Sign Up(PS:注册)"和"Sign In(PS:登录)"的区别?将它们作为按钮名称同时使用,会让用户点错按钮.出现上述问题并不是用户的 ...

  8. 【PAT】A1006 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, ...

  9. 【PAT - 甲级1006】Sign In and Sign Out (25分)(STLmap)

    题干: At the beginning of every day, the first person who signs in the computer room will unlock the d ...

最新文章

  1. php math函数
  2. Mysql大型数量下的数据库构建的30条建议
  3. 有关推挽输出、开漏输出、复用开漏输出、复用推挽输出以及上拉输入、下拉输入、浮空输入、模拟输入区别
  4. mysql主从技术_MySQL主从架构的实现
  5. java ndc_通过slf4j/log4j的MDC/NDC 实现日志追踪
  6. linux上dig命令,Linux dig命令(示例代码)
  7. 【数字逻辑设计】卡诺图
  8. python dict方法_python dict()方法学习笔记
  9. linux下qt生成dll,Qt 创建和使用动态链接库 - cibiren2011的专栏 - 博客频道 - CSDN.NET...
  10. react native 问题点
  11. Enolsoft PDF Converter with OCR激活版
  12. 陆维家具设计拆单软件
  13. java int转byte出现负数 byte转int的解决
  14. 在计算机中1 KB等于多少字节,字节、kb、MB、GB 等单位怎么换算的?1M等于多少kb,1g等于多少kb?...
  15. 1.firefox缺少flash插件
  16. 规划控制下的二阶段设计理论 -【多核服务价值链协同】
  17. 程序员的精确思维,左手数学右手编程
  18. 关于网页背景图怎样自动适应屏幕大小
  19. [Android] Codec paramter
  20. 青岛科技大学和青岛大学计算机专业,青岛科技大学和青岛大学哪个好呢?优势的专业分别是什么?...

热门文章

  1. 如何在 JS 中“深冻结”对象?
  2. for循环生成26个字母
  3. networkx学习(四) 小世界网络
  4. 【鸟哥杂谈】三分钟完成腾讯云部署emqx,公网访问自己的mqtt服务器
  5. vue使用饿了么upload组件实现下载功能
  6. 启动磁盘不能被分区或恢复成单个分区-解决了
  7. 2019酒驾、醉驾新标准!
  8. pymunk中怎么设置实体的线速度阻力系数和角速度阻力系数、初始线速度、角速度...
  9. 大数据之路:数据同步
  10. 电脑插入了一个加密U盘,拷贝东西,随后电脑就出现一个交换区的盘符,U盘拔走以后交换区还在怎么去掉?