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的更多相关文章

  1. 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, ...

  2. 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 ...

  3. PAT (Advanced Level) 1006. Sign In and Sign Out (25)

    简单题. #include<iostream> #include<cstring> #include<cmath> #include<algorithm> ...

  4. PTA (Advanced Level) 1004 Counting Leaves

    Counting Leaves A family hierarchy is usually presented by a pedigree tree. Your job is to count tho ...

  5. PTA (Advanced Level) 1020 Tree Traversals

    Tree Traversals Suppose that all the keys in a binary tree are distinct positive integers. Given the ...

  6. PTA(Advanced Level)1025.PAT Ranking

    To evaluate the performance of our first year CS majored students, we consider their grades of three ...

  7. 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 ...

  8. PTA (Advanced Level) 1008 Elevator

    Elevator The highest building in our city has only one elevator. A request list is made up with Npos ...

  9. PTA (Advanced Level) 1007 Maximum Subsequence Sum

    Maximum Subsequence Sum Given a sequence of K integers { N​1​​, N​2​​, ..., N​K​​ }. A continuous su ...

随机推荐

  1. 从kepware定时取web api内容

    using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; usin ...

  2. noip第18课作业

    1. 银行取款 [题目描述] 在现代文明社会中,大家在诸如银行办理业务.车站买票等活动时都很文明没有插队的现象,本着“先来先服务”的规矩. 新年马上到了,明明的爸爸打算上银行去取点钱,带着一向表现很好 ...

  3. 基于FPGA的I2C读写EEPROM

    I2C在芯片的配置中应用还是很多的,比如摄像头.VGA转HDMI转换芯片,之前博主分享过一篇I2C协议的基础学习IIC协议学习笔记,这篇就使用Verilog来实现EEPROM的读写,进行一个简单的I2 ...

  4. 《mysql必知必会》学习_第13章_20180803_欢

    第13章:分组过滤. P83 select count(*) as num_prods from products where vend_id=1003; #返回vend_id=1003的产品数目总值 ...

  5. 防Xss注入

    转自博客:https://blog.csdn.net/qq_21956483/article/details/54377947 1.什么是XSS攻击 XSS又称为CSS(Cross SiteScrip ...

  6. imooc movie

    node+mongodb 建站攻略(一期) 用的都是我熟悉的技术,看了别人的开发过程,自己也学到了一些新的知识 生成配置文件 开发结束后,可以使用bower init来生成前端的配置文件. 不过在bo ...

  7. AngularJS 路由 resolve属性

    当路由切换的时候,被路由的页面中的元素(标签)就会立马显示出来,同时,数据会被准备好并呈现出来.但是注意,数据和元素并不是同步的,在没有任何设置的情况下,AngularJS默认先呈现出元素,而后再呈现 ...

  8. 为什么在UDP包中不能获取发包方的地址

    首先,我们要先了解一下UDP包的结构. 图1 UDP报文格式 从图1,我们可以看出,从UDP包中,我们可以获取的信息只有源端口和目的地端口.我们不能获取到源IP因为报文中没有源IP.真正包含IP地址的 ...

  9. 58VIP账号发贴器

    因公司有招聘大量普工需求,需要大量简历资源,直接从58买一份简历动辄几块到几十块,如果做精准少则1块以上的点击.而且收到的简历不太精准,应公司需求写了一款自动发贴器.完全模拟人工发贴,经过一个月的测试 ...

  10. ASP.NET MVC 使用 Log4net 记录日志

    Log4net 介绍 Log4net 是 Apache 下一个开放源码的项目,它是Log4j 的一个克隆版.我们可以控制日志信息的输出目的地.Log4net中定义了多种日志信息输出模式.它可以根据需要 ...