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 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
题目解析
本题给出一天内登录机房的总人数m,之后给出m行数据,每行为一个人的登录信息,其中包括一个长度不超过15的id, 一个格式为HH:MM:SS的登录时间inTime,和一个格式为HH:MM:SS的登出时间outTime。
第一个登录机房的人将是开门者,最后一个登出机房的人将是锁门者,要求输出开门者与锁门者的id。
C++的string比较两个长度相等的字符串大小是由首位开始按位比较ASCII码,首位ASCII码大的字符串视为较大字符串,若首位相等边比较第二位,依次向后比较。者正好符合我们对HH:MM:SS类型的时间比较,较大的时间在字符串比较时依然较大,这样我们便可以将时间存为string直接进行比较。
#include <bits/stdc++.h>
using namespace std;
int main()
{
int m;
string unlockedId, lockedId, minTime = "24:00:00", maxTime = "00:00:00";
scanf("%d", &m); //输入登录总人数
for(int i = ; i < m; i++){
string id, inTime, outTime;
cin >> id >> inTime >> outTime; //输入登录者id 登录时间 登出时间
if(minTime > inTime){ //如果登录时间早于当早登录时间
minTime = inTime; //记录最早登录时间为当前登录时间
unlockedId = id; //记录开门者id为当前id
}
if(maxTime < outTime){ //如果登出时间晚于最晚登录时间
maxTime = outTime; //记录最晚登出时间为当前登出时间
lockedId = id; //记录锁门者id为当前id
}
}
cout << unlockedId << " " << lockedId << endl;
//输出开门者和锁门者的id
return ;
}
PTA (Advanced Level) 1006 Sign In and Sign Out的更多相关文章
- PTA(Basic Level)1006.Sign In and Sign Out
At the beginning of every day, the first person who signs in the computer room will unlock the door, ...
- PTA(Advanced Level)1036.Boys vs Girls
This time you are asked to tell the difference between the lowest grade of all the male students and ...
- PAT (Advanced Level) 1006. Sign In and Sign Out (25)
简单题. #include<iostream> #include<cstring> #include<cmath> #include<algorithm> ...
- PTA (Advanced Level) 1004 Counting Leaves
Counting Leaves A family hierarchy is usually presented by a pedigree tree. Your job is to count tho ...
- PTA (Advanced Level) 1020 Tree Traversals
Tree Traversals Suppose that all the keys in a binary tree are distinct positive integers. Given the ...
- PTA(Advanced Level)1025.PAT Ranking
To evaluate the performance of our first year CS majored students, we consider their grades of three ...
- PTA (Advanced Level) 1009 Product of Polynomials
1009 Product of Polynomials This time, you are supposed to find A×B where A and B are two polynomial ...
- PTA (Advanced Level) 1008 Elevator
Elevator The highest building in our city has only one elevator. A request list is made up with Npos ...
- PTA (Advanced Level) 1007 Maximum Subsequence Sum
Maximum Subsequence Sum Given a sequence of K integers { N1, N2, ..., NK }. A continuous su ...
随机推荐
- QOpenGLFunctions的使用(2)
QOpenGLFunctions的使用(2) 前一小结请参考:QOpenglFuncations(1) www.icmzn.com 本小节介绍相关的类: 1. The QGLContext class ...
- EBS 取消“是否提交另一项请求”提示
在使用EBS提交请求后,总要弹出“是否提交另一项请求”的提示,而我们往往选择“否”,这个提示就显得多余. 为了减轻这“多一步”的负担,取消“是否提交另一项请求”的提示,设置方法如下: 以下profil ...
- cxgrid回车移到下一个单元格
cxgrid回车移到下一个单元格 cxgrid回车移到下一个单元格 作用:表格式录入全键盘操作. 设置cxgrid1Dbtableview1.optionsBehavior.goToNextCel ...
- 行人检测(Pedestrian Detection)资源
一.论文 综述类的文章 [1]P.Dollar, C. Wojek,B. Schiele, et al. Pedestrian detection: an evaluation of the stat ...
- Spring Boot 应用系列 6 -- Spring Boot 2 整合Quartz
Quartz是实现定时任务的利器,Quartz主要有四个组成部分,分别是: 1. Job(任务):包含具体的任务逻辑: 2. JobDetail(任务详情):是对Job的一种详情描述: 3. Trig ...
- bootstrap基础学习小记(一)简介模板、全局样式
2011年,twitter的“一小撮”工程师为了提高他们内部的分析和管理能力,用业余时间为他们的产品构建了一套易用.优雅.灵活.可扩展的前端工具集--BootStrap.Bootstrap由MARK ...
- 从NetCore报错到MySql安全
之前项目在测试服务器上的一些接口时不时会报出下面的错误:(采用Abp框架) "SocketException: 你的主机中的软件中止了一个已建立的连接. STACK TRACE: at My ...
- 【react】当react框架遇上百度地图
百度地图官方文档的使用指导是这样说的:在页面中引入<script type="text/javascript" src="http://api.map.baid ...
- Python 爬虫(二十五) Cookie的处理--cookielib库的使用
Python中cookielib库(python3中为http.cookiejar)为存储和管理cookie提供客户端支持. 该模块主要功能是提供可存储cookie的对象.使用此模块捕获cookie并 ...
- eclipse安装STS遇到的问题
eclipse安装STS时,在eclipse marketplase中搜索STS没有结果,从官网下载STS包,然后安装提示找不到JAR包, 解决方式: eclipse需要和STS包版本一致,如果STS ...