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. Stm32外围模块编程初始化步骤

    Stm32外围模块编程初始化步骤: 一.外部中断 1)初始化 IO 口为输入. 这一步设置你要作为外部中断输入的 IO 口的状态,可以设置为上拉/下拉输入,也可以设置为浮空输入,但浮空的时候外部一定要 ...

  2. ExtJs 5.0需要注意的问题

    1.在网上查找到的一些例子当中,存在new Ext.grid.ColumnModel()这样的操作,在5.0当中这是不允许的,在5.0当中这个已经被设置为私有方法,不允许用户调用,在5.0中我们不需要 ...

  3. 浅谈Javascript中默认参数值的设置

    第一种: 1: function test(a,b){ 2: var a = arguments[0] ? arguments[0] : 1;//设置参数a的默认值为1 3: var b = argu ...

  4. leetcode@ [241] Different Ways to Add Parentheses (Divide and Conquer)

    https://leetcode.com/problems/different-ways-to-add-parentheses/ Given a string of numbers and opera ...

  5. 局域网Internet的共享

    局域网接入Internet,之后,在服务器安装共享代理软件,可以使客户机通过代理软件接入Internet. 局域网接入Internet 而目前几乎所有的浏览器.下载软件.信件收发软件都支持代理服务器. ...

  6. A Tour of Go Map literals

    Map literals are like struct literals, but the keys are required. package main import "fmt" ...

  7. 【Linux】多睡/少睡一小时!冬夏令时全解析

    多伦多2016年11月6日凌晨2点开始起时间调回一小时,时间到凌晨2点时自动跳回到1点,大家可以多睡一小时(或者多一小时写essay的时间)~ 多伦多2017年3月12日凌晨2点开始时间拨快一小时时间 ...

  8. webServices

    引用项目的配置文件: <system.serviceModel> <bindings> <basicHttpBinding> <!--旅游供应--> & ...

  9. grdgradient

    from http://gmt.soest.hawaii.edu/doc/5.2.1/grdgradient.html grdgradient grdgradient - Compute direct ...

  10. SQLite使用教程9 Select 语句

    http://www.runoob.com/sqlite/sqlite-select.html SQLite Select 语句 SQLite 的 SELECT 语句用于从 SQLite 数据库表中获 ...