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 ...
随机推荐
- Linux下复制粘贴快捷键
1. 在控制台下: 1.1.鼠标选中要复制的文本,按鼠标中键,即为复制 或者 1.2.复制命令 ...
- 关于贴友的一个书本页面简单布局(html+css)的实现
贴友需求:以html+css仿照书本的页面实现布局效果(见图) html代码: 1: <!-- 我的博客:http://www.ido321.com --> DOCTYPE HTML> ...
- HW6.18
public class Solution { public static void main(String[] args) { double[] array = {6.0, 4.4, 1.9, 2. ...
- Sort--快速排序
快速排序 1 public class QuickSort{ 2 3 public static int Partition(int[] a,int low,int high){ 4 int pivo ...
- FZU 2176 easy problem (DFS序+树状数组)
对于一颗树,dfs遍历为每个节点标号,在进入一个树是标号和在遍历完这个树的子树后标号,那么子树所有的标号都在这两个数之间,是一个连续的区间.(好神奇~~~) 这样每次操作一个结点的子树时,在每个点的开 ...
- Hadoop概念学习系列之hadoop、spark常备查询网址(二十九)
http://archive.apache.org/dist
- 再次踩bug:遍历删除list(java.util.ConcurrentModificationException)
再次踩bug:遍历删除list(java.util.ConcurrentModificationException) 使用 List<Long> list = new ArrayList& ...
- ALM11测试计划页面图解1
在 ALM 侧栏上的测试下方,选择测试计划. 在查看菜单中,选择测试网格或测试计划树. 在 ALM 侧栏上的测试下方,选择测试计划. 右键单击测试,并选择测试详细信息. 在测试计划树中选择主题文件夹, ...
- 转载 C#匿名函数 委托和Lambda表达式
转载原出处: http://blog.csdn.net/honantic/article/details/46331875 匿名函数 匿名函数(Anonymous Function)是表示“内联”方法 ...
- Emgu CV 高斯建模
Codeprivate void button1_Click(object sender, EventArgs e) { Emgu.CV.Capture cap = new Capture(" ...