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

题目的输出是输出所有人中最早开门的和最晚锁门的人

解法一:很容易想到的是ID_number Sign_in_time Sign_out_time作为一个结构体的元素,
struct info{
ID_number
Sign_in_time
Sign_out_time
}
vector<info> v;
将所有的信息存入容器中,利用sort函数,先根据Sign_in_time从小到大排序,输出第一个ID_number,再根据Sign_out_time从大到小排序,输出第一个ID_number。
 #include <iostream>
#include <string>
#include <algorithm>
#include <vector>
using namespace std;
struct info{
string ID_number;
string Sign_in_time;
string Sign_out_time;
};
bool unlock(info lhs,info rhs){
return lhs.Sign_in_time<rhs.Sign_in_time;
}
bool lock(info lhs,info rhs){
return lhs.Sign_out_time>rhs.Sign_out_time;
}
int main(int argc,char **argv){
info I;
string ID_number,Sign_in_time,Sign_out_time;
string unlock_ID,lock_ID;
vector<info> vi;
int N;
cin>>N;
for(int i=;i<N;i++){
cin>>ID_number>>Sign_in_time>>Sign_out_time;
I.ID_number=ID_number;I.Sign_in_time=Sign_in_time;I.Sign_out_time=Sign_out_time;
vi.push_back(I);
}
std::sort(vi.begin(),vi.end(),unlock);
unlock_ID=(*vi.begin()).ID_number;
std::sort(vi.begin(),vi.end(),lock);
lock_ID=(*vi.begin()).ID_number;
cout<<unlock_ID<<" "<<lock_ID<<endl;
return ;
}
C++字符串比较很给力!!

解法二:我只要所有人中Sign_in_time最小和Sign_out_time最大的,所以初始化所有人中unlock_time=”23:59:59“,lock_time=”00:00:00“

每输入一个ID_number Sign_in_time Sign_out_time,若Sign_in_time <= unlock_time,则unlock_time = Sign_in_time, In_ID_number  = ID_number,

若Sign_out_number >= lock_time,则lock_time = Sign_out_time, Out_ID_number  = ID_number,

 #include <iostream>
#include <cstring>
using namespace std; int main(){
char mins[],maxs[], str[];
char minT[] = "23:59:59";
char maxT[] = "00:00:00";
char tmp_in[], tmp_out[];
int num, i; cin >> num;
for(i = ; i < num; i++){
cin >> str >> tmp_in >> tmp_out;
if(strcmp(tmp_in, minT) <= ){
strcpy(mins, str);
strcpy(minT, tmp_in);
}
if(strcmp(tmp_out, maxT) >= ){
strcpy(maxs, str);
strcpy(maxT, tmp_out);
}
}
cout << mins << " " << maxs << endl;
return ;
}
 #include <iostream>
#include <cstring>
#include <string>
using namespace std; int main(){
string mins, maxs, str;
string minT = "23:59:59";
string maxT = "00:00:00";
string tmp_in, tmp_out;
int num, i; cin >> num;
for(i = ; i < num; i++){
cin >> str >> tmp_in >> tmp_out;
if(tmp_in <= minT){
mins = str;
minT= tmp_in;
}
if(tmp_out >= maxT){
maxs = str;
maxT = tmp_out;
}
}
cout << mins << " " << maxs << endl;
return ;
}

C++字符串比较很给力!!

以前比较时间(   时:分:秒  )总是先比较小时,再比较分钟,最后比较秒,现在发现可以直接把它当做字符串,通过比较字符串来比较时间的先后。

												

pat 1006 Sign In and Sign Out (25)的更多相关文章

  1. PAT (Advanced Level) Practice 1006 Sign In and Sign Out (25 分) 凌宸1642

    PAT (Advanced Level) Practice 1006 Sign In and Sign Out (25 分) 凌宸1642 题目描述: At the beginning of ever ...

  2. 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 ...

  3. 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 ...

  4. 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 ...

  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 the co ...

  6. 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 ...

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

  8. 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 ...

  9. pat1006. Sign In and Sign Out (25)

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

  10. 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 ...

随机推荐

  1. php框架Symfony资料

    1.http://snippets.symfony-project.org/snippets/tagged/criteria/order_by/date 2.Propel API: http://ap ...

  2. 挑战树莓派:谁才是Geek最爱的开发板?

    树莓派(Raspberry Pi)是一块跟信用卡差不多大小的开发板,它的初衷是以低廉的硬件和开源软件扶持一些落后地区的电脑科学教育.由于它在性能和价格方面有一个很好的平衡点,所以很多硬件玩家也想买一个 ...

  3. 【翻译】Android避免内存泄露(Activity的context 与Context.getApplicationContext)

    原谅地址:http://android-developers.blogspot.com/2009/01/avoiding-memory-leaks.html ,英文原文在翻译之后 Android 应用 ...

  4. nyoj 218 Dinner

    Dinner 时间限制:100 ms  |  内存限制:65535 KB 难度:1   描述 Little A is one member of ACM team. He had just won t ...

  5. Dom深入浅出

    Dom1级提供了一个Node接口,该接口将由Dom中所有节点类型(包括元素节点.文本节点.属性节点等12种)实现,而js是作为Node类型来实现的,js中的所有节点类型的继承自Node类型, 所以它们 ...

  6. Sql sp_executesql 参数问题

    DECLARE @name NVARCHAR(30), @sql NVARCHAR(300)set @sql= N'SELECT TOP 1 @n=EmpName from dbo.Emp' exec ...

  7. mybatis 打印sql log配置

    mybatis 打印sql log, 方便调试.如何配置呢? log4j.xml : <!-- 打印sql start --> <appender name="IBatis ...

  8. 基于EF创建数据库迁移

    通过创建的实体类和DbContext类利用EF的Code First数据库迁移创建数据库. 下面看代码. 一.先创建实体类 我先添加一个BaseEntity,里面就一个属性 [Key] public ...

  9. linux设置tomcat开机自动启动

    1.修改/etc/rc.d/rc.local,使用vi /etc/rc.d/rc.local 命令2.在/etc/rc.d/rc.local文件最后添加下面两行脚本 export JAVA_HOME= ...

  10. 04---XML编程整理

    一.XML概述       XML(eXtensible Markup Language),可扩展标记语言,       被设计的宗旨是传输数据,而非显示数据       W3C发布的,目前遵循1.0 ...