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. uvalive 4795 Paperweight

    题意:给出一个5个顶点的多面体以及多面体内一点P.求让 多面体不同的方式(即以不同的面)放在地面上,设这个着地的面为A,多面体重心在A上的投影为B,在保证B在A内部且距离A的各个边界不小于0.2的前提 ...

  2. 1.2CPU和GPU的设计区别

    CPU和GPU之所以大不相同,是由于其设计目标的不同,它们分别针对了两种不同的应用场景.CPU需要很强的通用性来处理各种不同的数据类型,同时又要逻辑判断又会引入大量的分支跳转和中断的处理.这些都使得C ...

  3. leetcode@ [129] Sum Root to Leaf Numbers (DFS)

    https://leetcode.com/problems/sum-root-to-leaf-numbers/ Given a binary tree containing digits from 0 ...

  4. [学姿势]实验室搬砖+node学习

    这周开始进行收尾工作,我当然没有进行核心技术的开发,主要负责的是对web端进行展示上的修修补补,主要包括添加VLC播放器.rtsp视频流以及一些js细节. 1.VLC 全称为Video Lan Cli ...

  5. 100+经典Java面试题及答案解析

    面向对象编程(OOP) Java是一个支持并发.基于类和面向对象的计算机编程语言.下面列出了面向对象软件开发的优点: 代码开发模块化,更易维护和修改. 代码复用. 增强代码的可靠性和灵活性. 增加代码 ...

  6. Android实例-如何使用系统剪切板(XE8+小米2)

    结果: 发现个问题,就是粘贴时会清除之前的信息. unit Unit1; interface uses System.SysUtils, System.Types, System.UITypes, S ...

  7. 把存储过程获取的数据输出到报表的html模板中

    制作报表的html模板 <HTML><meta http-equiv="Content-Type" content="text/html; charse ...

  8. angular中的promise

    angular中的promise用法 标签(空格分隔): angular 前言 Promise其实是一个规范,用类似then().then()这样的链式调用形式来处理因为异步带来意大利面条式的代码(多 ...

  9. ASP.NET MVC- EF返回连接池用ADO.NET方式访问数据库

    用习惯了ADO.NET的方式去访问数据库,虽然ADO.NET写的代码没有EF简洁,可是也并不麻烦.而且EF在进行多表查询的那种方式是,EF需要先去数据库里定义外键,再进去一次代码生成,然后才能用INC ...

  10. android 五子棋开发

    两天完成基本功能,再对其进行细节bug优化,本小白的思路. 思路: 1.用canvas绘制棋盘:得到手机的分辨率.棋盘大小为19*19.将手机宽屏分为21份,取中间19份为棋盘.上下空白位置为按钮功能 ...