pat 1006 Sign In and Sign Out (25)
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)的更多相关文章
- 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 ...
- 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 ...
- 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 ...
- 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 ...
- 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 ...
- 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 ...
- 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 ...
- 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 ...
- pat1006. Sign In and Sign Out (25)
1006. Sign In and Sign Out (25) 时间限制 400 ms 内存限制 65536 kB 代码长度限制 16000 B 判题程序 Standard 作者 CHEN, Yue ...
- 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 ...
随机推荐
- NOIP2005 过河
过河 (river.pas/c/cpp) [问题描述] 在河上有一座独木桥,一只青蛙想沿着独木桥从河的一侧跳到另一侧.在桥上有一些石子,青蛙很讨厌踩在这些石子上.由于桥的长度和青蛙一次跳过的距离都是正 ...
- html中a标签中的onclick和href的使用
1. 链接的 onclick 事件被先执行,其次是 href 属性下的动作(页面跳转,或 javascript 伪链接): 假设链接中同时存在 href 与 onclick,如果想让 href 属性下 ...
- pollard_rho和Miller_Rabin
Miller_Rabin就是以概论大小来判断素数 可以判断2^63范围的数 pollard_rho推荐两个很好的博客来理解:整数分解费马方法以及Pollard rho和[ZZ]Pollard Rho算 ...
- Linux 下文件名乱码(无效的编码)的解决办法
文件是在WIndows 下创建的,Windows 的文件名中文编码默认为GBK,而Linux中默认文件名编码为UTF8,由于编码 不一致所以导致了文件名乱码的问题,解决这个问题需要对文件名进行转码. ...
- HW5.30
public class Solution { public static void main(String[] args) { for(int i = 3; i <= 1000; i++) i ...
- poj 3250 Bad Hair Day【栈】
Bad Hair Day Time Limit: 2000MS Memory Limit: 65536K Total Submissions: 15922 Accepted: 5374 Des ...
- hdoj 2046 骨牌铺方格
骨牌铺方格 Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)Total Submi ...
- 把SVN添加到windows服务
sc create SVN_Service binpath= "D:\DevTools\Subversion\bin\svnserve.exe --service --root D:\Dev ...
- 手把手教你入门mac idea
一.前沿 去年入职后, 公司有很多人使用的是idea , 而不是eclipse. 之前就想转向idea, 但一直没转过来~~原因是团队的人提倡用开源eclipse.现在下定决心转向idea. 虽然, ...
- 【Android 应用开发】Activity 状态保存 OnSaveInstanceState參数解析
作者 : 韩曙亮 转载请著名出处 : http://blog.csdn.net/shulianghan/article/details/38297083 一. 相关方法简单介绍 1. 状态保存方法演示 ...