1006. Sign In and Sign Out (25)
来源:互联网 发布:手机淘宝信誉评级在哪 编辑:程序博客网 时间:2024/06/08 01:15
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
题目分析:由于不知道m的具体范围,采用输入一个就比较一个的策略,比较方法为字符串比较。
#include <stdio.h>#include <stdlib.h>#include <string.h>struct person{ char id[16]; char signInTime[9]; char signOutTime[9];}firstOne, lastOne,tmp; //分别表示解锁的人、加锁的的人、中间变量void exchange(struct person *a, struct person *b) { //把b的结构体的所有值赋给a strcpy(a->id, b->id); strcpy(a->signInTime, b->signInTime); strcpy(a->signOutTime, b->signOutTime);}int main(){ int m, i; scanf("%d ", &m); scanf("%s %s %s", tmp.id, tmp.signInTime, tmp.signOutTime); strcpy(firstOne.id, tmp.id); //在for之前是初始化 strcpy(lastOne.id, tmp.id); strcpy(firstOne.signInTime, tmp.signInTime); strcpy(lastOne.signInTime, tmp.signInTime); strcpy(firstOne.signOutTime, tmp.signOutTime); strcpy(lastOne.signOutTime, tmp.signOutTime); for(i = 0; i < m - 1; i++) { //由于不知道m的范围,只能采用输入一个就比较一个的策略 scanf("%s %s %s", tmp.id, tmp.signInTime, tmp.signOutTime); if(strcmp(tmp.signInTime, firstOne.signInTime) < 0) exchange(&firstOne, &tmp); if(strcmp(tmp.signOutTime, lastOne.signOutTime) > 0) exchange(&lastOne, &tmp); } printf("%s %s", firstOne.id, lastOne.id); return 0;}
- 1006. Sign In and Sign Out (25)
- 1006. Sign In and Sign Out (25)
- 1006. Sign In and Sign Out (25)
- 1006. Sign In and Sign Out (25)
- 1006. Sign In and Sign Out (25)
- 1006. Sign In and Sign Out (25)
- 1006. Sign In and Sign Out (25)
- 1006. Sign In and Sign Out (25)
- 1006. Sign In and Sign Out (25)
- 1006. Sign In and Sign Out (25)
- 1006. Sign In and Sign Out (25)
- 1006. Sign In and Sign Out (25)
- 1006. Sign In and Sign Out (25)
- 1006. Sign In and Sign Out (25)
- 1006. Sign In and Sign Out (25)
- 1006. Sign In and Sign Out (25)
- 1006. Sign In and Sign Out (25)
- 1006. Sign In and Sign Out (25)
- 欢迎使用CSDN-markdown编辑器
- ajax的data传参的两种方式
- How to Secure an Android App 如何保护Android应用程序
- 平面设计之展示牌篇
- c语言实现ping
- 1006. Sign In and Sign Out (25)
- 用lua输出斐波那契fibonacci数列 : 0, 1,1, 2, 3, 5, 8, 13, 21, 34, 55, 89
- C语言及程序设计初步—第7讲
- 大型网站架构之分布式消息队列
- OkHttp:Java 平台上的新一代 HTTP 客户端
- Linux设备驱动第三天(字符设备驱动、cdev)
- 海狐联合创始人王哲: 做产品做市场,让用户体验更爽
- Android 属性动画 源码解析 深入了解其内部实现
- poj 3006 Dirichlet's Theorem on Arithmetic Progressions