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. foreach控件的运用(非原创)http://blog.chinaunix.net/uid-26884465-id-3416869.html

    人们对从认识事物都有一个具体到抽象的过程,学习Jmeter也不例外,通过一个实例来进行学习,一方面可以让初学者有所见即所得的信心,另一方面,其实也是在初学者心中留下了对这事物的一个朦胧的印象,这在以后 ...

  2. What makes for effective detection proposals? 论文解析

    1 介绍(INTRODUCTION) 本文主要对最近的 proposal 检测方法做一个总结和评价.主要是下面这些方法.  2 Detection Proposal 方法(DETECTION PROP ...

  3. CentOS7下启用网卡

    [root@localhost network-scripts]# ls ifcfg-ens99 ifdown-ippp ifdown-sit ifup-bnep ifup-plip ifup-Tea ...

  4. Django:全文检索功能可参考博客

    https://blog.csdn.net/AC_hell/article/details/52875927 https://www.zmrenwu.com/courses/django-blog-t ...

  5. Markdown中怎么上传图片

    在网站中使用了Markdown编辑器,但是不能支持图片的直接粘贴

  6. C#为什么不能像C/C++一样的支持函数只读传参

    C#为什么不能像C/C++一样的支持函数只读传参? 这个问题其实问的人挺多的,我自己也经常想实现这个功能,但是发现总是那么的不尽人意. 有些人倒是给出了一下答案,但是都不能很好的解决像C/C++一样的 ...

  7. WPF学习笔记(2):准确定位弹出窗

    效果图:使弹出的列表框紧随在单元格的下边缘. 第一次,尝试在XAML中设置Popup的定位方式:Placement="Mouse".基本能够定位,但当在输入前移动鼠标,列表框就会随 ...

  8. 由VC2010与VC2017数据结构差异造成的程序错误

    内容:VC2010和VC2017的标准库中,string(或wstring)的数据结构和操作有所不同,所以在将这两种数据作为参数在两个系统产生的函数中传递时会出现乱码(string和wstring在2 ...

  9. UVA10829 L-Gap Substrings(后缀数组+ST表)

    后缀数组+ST表. 代填的坑. \(Code\ Below:\) #include <bits/stdc++.h> #define ll long long using namespace ...

  10. [vuejs] vue2.0-layer-mobile移动端弹层

    vue2.0-layer-mobile移动端弹层 本次组件升级支持slot内容分发功能,实现高定制内容风格的弹层 安装方法 npm install vue2-layer-mobile -S 初始化 i ...