A1006. 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:
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 结构体可以直接赋值,但成员中有数组时,还需要单独拷贝。
A1006. Sign In and Sign Out的更多相关文章
- 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 the co ...
- PAT1006:Sign In and Sign Out
1006. Sign In and Sign Out (25) 时间限制 400 ms 内存限制 65536 kB 代码长度限制 16000 B 判题程序 Standard 作者 CHEN, Yue ...
- PAT 甲级 1006 Sign In and Sign Out (25)(25 分)
1006 Sign In and Sign Out (25)(25 分) At the beginning of every day, the first person who signs in th ...
- PTA (Advanced Level) 1006 Sign In and Sign Out
Sign In and Sign Out At the beginning of every day, the first person who signs in the computer room ...
- PAT Sign In and Sign Out[非常简单]
1006 Sign In and Sign Out (25)(25 分) At the beginning of every day, the first person who signs in th ...
- PAT甲 1006. Sign In and Sign Out (25) 2016-09-09 22:55 43人阅读 评论(0) 收藏
1006. Sign In and Sign Out (25) 时间限制 400 ms 内存限制 65536 kB 代码长度限制 16000 B 判题程序 Standard 作者 CHEN, Yue ...
- 1006 Sign In and Sign Out (25)(25 分)思路:普通的时间比较题。。。
1006 Sign In and Sign Out (25)(25 分) At the beginning of every day, the first person who signs in th ...
- pat1006. Sign In and Sign Out (25)
1006. Sign In and Sign Out (25) 时间限制 400 ms 内存限制 65536 kB 代码长度限制 16000 B 判题程序 Standard 作者 CHEN, Yue ...
- pat 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 the com ...
- PAT甲级——1006 Sign In and Sign Out
PATA1006 Sign In and Sign Out At the beginning of every day, the first person who signs in the compu ...
随机推荐
- 剑指offer(18)二叉搜索树的后续遍历
题目: 输入一个整数数组,判断该数组是不是某二叉搜索树的后序遍历的结果.如果是则输出Yes,否则输出No.假设输入的数组的任意两个数字都互不相同. 思路: 以最后一个节点为根,从头往后找到第一个大于根 ...
- 老男孩python学习自修第六天【pycharm的使用】
1.在工程右键可选新建文件夹,包盒python文件 文件夹和包的区别在于,包包含一个空的__init__.py文件,而文件夹没有 2.pycharm的断点调试 点击Debug表示进入调试状态 点击Re ...
- pycharm 破解密码
server选项里边输入 http://idea.imsxm.com/
- Servlet3.0上传
1.上传对表单限制 *method=post *Enctype=multipart/form-data,它的默认值是:application/x-www-form-urlencoded 表单中需要添加 ...
- java JSP自定义标签
来至: http://blog.csdn.net/jiangwei0910410003/article/details/23915373 http://blog.csdn.net/jiangwei09 ...
- 做接口自动化时候,一些登录头信息可以通过aop的方式进行增强
做接口自动化时候,一些登录头信息可以通过aop的方式进行增强
- 使用update可以防止并发问题(保证数据的准确性),如果使用select会产生并发问题 ; select * from xx for update 给查询开启事务,默认情况下是没有事物的
update可以锁住数据防止数据被更新且导致与查询出的数据有误差,如果响应条数为0.说明更新失败 则可以回滚事务;
- python 文件下载
为了演示urllib3的使用,我们这里将会从一个网站下载两个文件.首先,需要导入urllib3库: import urllib3 这两个文件的源url为: url1 = 'http://earthqu ...
- 洛谷P1226 【模板】快速幂||取余运算
题目描述 输入b,p,k的值,求b^p mod k的值.其中b,p,k*k为长整型数. 输入输出格式 输入格式: 三个整数b,p,k. 输出格式: 输出“b^p mod k=s” s为运算结果 S1: ...
- 提高SqlServer数据库的安全性,禁用掉sa账户
Sqlsever 数据库有两种登陆身份验证模式,一种是windows身份验证:一种是sqlserver 账户验证模式,在sqlserver 账户验证模式中,sa账户是大家所熟知的,并且sa也是内置的默 ...