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
题目分析:给定数据排序 ,直接利用vector对结构体排序 将比较函数重写就可以了
注意sort中比较函数 返回true是不交换的 鉴于现在我水平较低 之后会尝试分析 源码的(大概
#include<iostream>
#include<string>
#include<stdlib.h>
#include<vector>
#include<algorithm>
using namespace std;
#define MaxNum 1
typedef struct Node {
string ID_numebr;
string Sign_in_time;
string Sign_out_time;
}S;
typedef struct Time {
int H;
int M;
int S;
}T;
T t1, t2;
int Atoi(string str, int i, int j)
{
int num = ;
while (i<j)
{
num = num * + str[i] - '';
i++;
}
return num;
}
bool comp2(const S& a, const S& b)
{ t1.H = Atoi(a.Sign_out_time, , );
t1.M = Atoi(a.Sign_out_time, , );
t1.S = Atoi(a.Sign_out_time, , );
t2.H = Atoi(b.Sign_out_time, , );
t2.M = Atoi(b.Sign_out_time, , );
t2.S = Atoi(b.Sign_out_time, , );
if (t1.H > t2.H)
return true;
else if (t1.H == t2.H && t1.M > t2.M)
return true;
else if (t1.M == t2.M && t1.S > t2.S)
return true;
else
return false;
} bool comp1(const S& a, const S& b)
{ t1.H = Atoi(a.Sign_in_time, , );
t1.M = Atoi(a.Sign_in_time, , );
t1.S = Atoi(a.Sign_in_time, , );
t2.H = Atoi(b.Sign_in_time, , );
t2.M = Atoi(b.Sign_in_time, , );
t2.S = Atoi(b.Sign_in_time, , );
if (t1.H < t2.H)
return true;
else if (t1.H == t2.H && t1.M < t2.M)
return true;
else if (t1.M == t2.M && t1.S < t2.S)
return true;
else
return false;
} int main()
{
vector<Node> N;
S s;
int n;
cin >> n;
for (int i = ; i < n; i++)
{
cin >> s.ID_numebr >> s.Sign_in_time >> s.Sign_out_time;
N.push_back(s);
}
sort(N.begin(), N.end(), comp1);
cout << N[].ID_numebr<<" ";
sort(N.begin(), N.end(), comp2);
cout << N[].ID_numebr;
return ;
}
1006 Sign In and Sign Out (25 分)的更多相关文章
- 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 ...
- 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(25 分)
1006 Sign In and Sign Out(25 分) At the beginning of every day, the first person who signs in the com ...
- 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) 2016-09-09 22:55 43人阅读 评论(0) 收藏
1006. Sign In and Sign Out (25) 时间限制 400 ms 内存限制 65536 kB 代码长度限制 16000 B 判题程序 Standard 作者 CHEN, Yue ...
- 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 ...
- 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 ...
随机推荐
- flask 设置https请求 访问flask服务器
学习过程中想要学教程中一样,做个假的微信公众号推送,不过去了微信开发文档怎么一直说需要https的请求(教学中没有说需要https,一直是http) 但是我的服务器只能使用http请求访问,如果硬是要 ...
- 【10】openlayers 视图view
创建地图: //View对象代表地图的简单2D视图 //创建view let view = new ol.View({ center:[109,34],//视图的初始中心 maxZoom:18,//最 ...
- Java集合04——fail-fast&fail-safe 详解
在前几个回合中,我们已经详细了解过了 Java 集合中的List.Set 和 Map,对这部分内容感兴趣的朋友可以关注我的公众号「Java面典」了解.今天我们将为各位介绍集合的失败机制--fail-f ...
- c++第一章1.6
测试已完成(bingo) 1 [单选题] 下面代码能够实现交换操作的函数有( ) A. swap(int a,int b) { int t=a;a=b;b=t;} B. swa ...
- [BlueZ] 3、使用 meshctl 连接控制一个 sig mesh 灯
目录 前言 1.准备工作 2.meshctl 连接.配置.控制 sig mesh 灯 3.最终效果: LINKS 前言 本文介绍如何使用 meshctl 配对.连接.控制一个 sig mesh 球泡灯 ...
- C++ 小练习,一个整型数字的处理
#define _CRT_SECURE_NO_WARNINGS #include <stdio.h> //输入一个任意位数的int整数,并判断该整数的位数,并输出每一位数(每个数字中间用空 ...
- webpack资料,还需整理
参考地址: https://github.com/ruanyf/webpack-demos#demo01-entry-file-source http://www.jianshu.com/p/4df9 ...
- 龙生九子-浅谈Java的继承
龙生九子-浅谈Java的继承 书接上回,我们之前谈过了类和对象的概念,今天我来讲一讲面向对象程序设计的另外一个基本概念-继承 目录 为什么需要继承 自动转型与强制转型 继承能干啥 复写和隐藏 supe ...
- LeetCode43,一题让你学会高精度算法
本文始发于个人公众号:TechFlow,原创不易,求个关注 今天是LeetCode系列第22篇文章,今天讲的内容是高精度算法. 今天和大家讨论的算法是高精度,对应的LeetCode是第43题.题面其实 ...
- Windows主机与centOS虚拟机之间"ping不通"
为什么要遇到这个问题 这是我重新安装centOS7.5虚拟机之后遇到的问题——我需要安装一个SecureCRT工具,结果主机与虚拟机没有ping通. 在安装这个工具之前需要进行主机与虚拟机的相互pin ...