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<cstdio>
#include<iostream>
#include<string.h>
using namespace std;
typedef struct rcd{
char id[];
int hh,mm,ss;
}record;
int isLater(record a, record b){
if(a.hh > b.hh){
return ;
}else if(a.hh == b.hh && a.mm > b.mm){
return ;
}else if(a.hh == b.hh && a.mm == b.mm && a.ss > b.ss){
return ;
}else{
return ;
}
}
int main(){
int M;
record rd1, rd2, temp1, temp2;
rd1.ss = ;
rd1.mm = ;
rd1.hh = ;
rd2.ss = ;
rd2.mm = ;
rd2.hh = ;
scanf("%d", &M);
for(int i = ; i < M; i++){
scanf("%s%d:%d:%d %d:%d:%d", temp1.id, &(temp1.hh), &(temp1.mm), &(temp1.ss), &(temp2.hh), &(temp2.mm), &(temp2.ss));
strcpy(temp2.id, temp1.id);
if(isLater(rd1, temp1)){
strcpy(rd1.id, temp1.id);
rd1 = temp1;
}
if(isLater(temp2, rd2)){
strcpy(rd2.id, temp2.id);
rd2 = temp2;
}
}
printf("%s %s", rd1.id, rd2.id);
cin >> M;
return ;
}

总结:

1、本题主要在于选择合适的数据结构存储每一条信息。

2、scanf函数,%s读取字符串时遇到空格换行符结束(会自动加\0),字符数组不用取地址符。

3、struct 结构体可以直接赋值,但成员中有数组时,还需要单独拷贝。

最新文章

  1. 【leetcode】Insertion Sort List (middle)
  2. web技术人员-推荐书籍
  3. HTML-003-模拟IDE代码展开收起功能简单示例
  4. jQuery.validator 详解
  5. openStack reboot调试
  6. android 小方法
  7. UML——动态建模
  8. 数据结构(主席树):COGS 2213. K个串
  9. hdu 2846
  10. 第001篇——C#学习计划开启
  11. Window及document对象的区别
  12. oracle 取头十条数据
  13. C语言之复杂链表的复制(图示详解)
  14. 19,CSS 滤镜
  15. 归并排序之python
  16. windows系统中配置多版本anaconda
  17. 深入理解Spring AOP之二代理对象生成
  18. 使用cookie记录页面跳转次数,然后从最后一级页面跳转回首页面
  19. Galaxy S10使用几乎零黑边框的OLED显示屏
  20. mysql-8.0.11-winx64 免安装版配置方法

热门文章

  1. IIS下载地址
  2. cordova微信支付回调App闪退
  3. python学习笔记(12)--程序设计方法学
  4. python 钉钉机器人发送消息
  5. eclipse 基础快捷键。
  6. php1
  7. Hibernate 连接不同数据库的方言
  8. Lodop导出图片和打印机无关,测试是否有关
  9. JavaEE进阶集锦(持续更新中)
  10. 微信小程序——报错汇总