PAT1006
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:
测试用例由一个正整数M开始,表示记录的数量,接下来有M行,每一行的格式如下
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.
给出的时间格式是HH:MM: SS,ID不会超过15个字符
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.
对于每个测试用例,输出一行,解锁和锁的人的ID
The two ID numbers must be separated by one space.
两个ID必须用一个空格分开
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
自己的代码太low了,我去,我干啥要一个个读取,干嘛要一个个去比较,我是不是蠢货啊。
这里推荐直接字符串比较就可以了。我真的是,写了一大堆才发现自己有多蠢。。。这种错误不能犯第二次,下一次一定要记住。下面是网上的代码,真的很简练很爽。
#include<stdio.h>
#include<string.h>
int main(){
char lkman[],unlkman[];
char id[],in[],out[];
char fst[]={"24:00:00"},last[]={"00:00:00"};
int i,j,n;
scanf("%d",&n);
for(i=;i<n;i++){
scanf("%s %s %s",id,in,out);
if(strcmp(in,fst)<){
strcpy(fst,in);
strcpy(unlkman,id);
}
if(strcmp(out,last)>){
strcpy(last,out);
strcpy(lkman,id);
}
}
printf("%s %s\n",unlkman,lkman);
return ;
}
代码转载自:http://blog.csdn.net/sup_heaven/article/details/8451669
PAT1006的更多相关文章
- PAT1006:Sign In and Sign Out
1006. Sign In and Sign Out (25) 时间限制 400 ms 内存限制 65536 kB 代码长度限制 16000 B 判题程序 Standard 作者 CHEN, Yue ...
- pat1006. Sign In and Sign Out (25)
1006. Sign In and Sign Out (25) 时间限制 400 ms 内存限制 65536 kB 代码长度限制 16000 B 判题程序 Standard 作者 CHEN, Yue ...
- 一天两道PAT(2)1005,1006
今天的pat1006没什么好说的.就记录一下1005的状况.先上题目. 卡拉兹(Callatz)猜想已经在1001中给出了描述.在这个题目里,情况稍微有些复杂. 当我们验证卡拉兹猜想的时候,为了避免重 ...
随机推荐
- python基础(三)--列表、元组、字典
一.列表: 有序序列,支持索引.切片.循环(for,while) 元素可以被修改: 元素可以是任何数据类型(数字,字符串,列表,布尔值...),可以嵌套: ##增 1.append(object) ...
- tomcat下同时部署两个项目不能正常启动的问题
在部署两个项目,这两个项目都是采用了一个框架,只是业务系统进行了修改.部署的时候发现启动有问题.会报类似下边的错误 Web app root system property already set t ...
- POJ1113 Wall 凸包
题目大意:建立围墙将城堡围起来,要求围墙至少距离城堡L,拐角处用圆弧取代,求围墙的长度. 题目思路:围墙长度=凸包周长+(2*PI*L),另外不知道为什么C++poj会RE,G++就没问题. #inc ...
- 有关android安全性的问题--代码混淆
转自:http://www.cnblogs.com/dream-sky/archive/2012/11/15/2771648.html 在project.properties里加上 proguar ...
- spring管理事务需要注意的
org.springframework.transaction.NoTransactionException: No transaction aspect-managed TransactionSta ...
- apache 不执行PHP,显示代码
首先检查是否安装PHP,已经安装过的话,先执行 locate libphp5.so 查看APACHE是否有SO文件,如果没有,那就要重装PHP了,先执行php -i | grep configure ...
- js第一天 点击按钮显示与隐藏
<!DOCTYPE html><html> <head> <meta charset="utf-8" /> <title> ...
- json格式数据,将数据库中查询的结果转换为json, 然后调用接口的方式返回json(方式一)
调用接口,无非也就是打开链接 读取流 将结果以流的形式输出 将查询结果以json返回,无非就是将查询到的结果转换成jsonObject ================================ ...
- hdu_4507_吉哥系列故事——恨7不成妻(鬼畜数位DP)
题目连接:http://acm.hdu.edu.cn/showproblem.php?pid=4507 题意:中文,不解释,注意的是求的是合法数字的平方和,即(a+b+c+……)^2 题解:数位DP, ...
- Django:之BBS项目
首先新建一个BBSProject项目,在建一个app,把app导入到项目中. 在项目BBSProject中的settings.py中, INSTALLED_APPS = [ 'django.contr ...