problem

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

tip

anwser

#include <bits/stdc++.h>
using namespace std; string firstName, lastName, firstTime, lastTime; bool CompTime(int a1, int b1, int c1, int a2, int b2, int c2){
if (a1 == a2){
if(b1 == b2)
return c1 < c2;
else return b1 < b2;
}else return a1 < a2;
} bool CalTime(string timeA, string timeB){
int a1, a2, b1, b2, c1, c2;
int tt;
a1 = (timeA[0]-48)*10 + timeA[1]-48;
a2 = (timeB[0]-48)*10 + timeB[1]-48; b1 = (timeA[3]-48)*10 + timeA[4]-48;
b2 = (timeB[3]-48)*10 + timeB[4]-48; c1 = (timeA[6]-48)*10 + timeA[7]-48;
c2 = (timeA[6]-48)*10 + timeA[7]-48; return CompTime(a1, b1, c1, a2, b2, c2);
} int main()
{
// freopen("test.txt", "r", stdin);
int N;
cin>>N;
string x, y, z;
for(int i = 0; i < N; i++){
cin>>x>>y>>z;
// cout<<x<<y<<z<<endl;
if(i == 0) {
firstName = lastName = x;
firstTime = y;
lastTime = z;
}else{
if(CalTime(y, firstTime)){
firstTime = y;
firstName = x;
}
if(CalTime(lastTime, z)){
lastTime = z;
lastName = x;
}
}
} cout<<firstName<<" "<<lastName;
return 0;
} /*
3
CS301111 15:30:28 17:00:10
SC3021234 08:00:00 11:25:25
CS301133 21:45:00 21:58:40
*/

experience

string 函数 :

// string::find_first_of
#include <iostream> // std::cout
#include <string> // std::string
#include <cstddef> // std::size_t int main ()
{
std::string str ("Please, replace the vowels in this sentence by asterisks.");
std::size_t found = str.find_first_of("aeiou");
while (found!=std::string::npos)
{
str[found]='*';
found=str.find_first_of("aeiou",found+1);
} std::cout << str << '\n'; return 0;
}
// string::find
#include <iostream> // std::cout
#include <string> // std::string int main ()
{
std::string str ("There are two needles in this haystack with needles.");
std::string str2 ("needle"); // different member versions of find in the same order as above:
std::size_t found = str.find(str2);
if (found!=std::string::npos)
std::cout << "first 'needle' found at: " << found << '\n'; found=str.find("needles are small",found+1,6);
if (found!=std::string::npos)
std::cout << "second 'needle' found at: " << found << '\n'; found=str.find("haystack");
if (found!=std::string::npos)
std::cout << "'haystack' also found at: " << found << '\n'; found=str.find('.');
if (found!=std::string::npos)
std::cout << "Period found at: " << found << '\n'; // let's replace the first needle:
str.replace(str.find(str2),str2.length(),"preposition");
std::cout << str << '\n'; return 0;
}
// string::substr
#include <iostream>
#include <string> int main ()
{
std::string str="We think in generalities, but we live in details.";
// (quoting Alfred N. Whitehead) std::string str2 = str.substr (3,5); // "think" std::size_t pos = str.find("live"); // position of "live" in str std::string str3 = str.substr (pos); // get from "live" to the end std::cout << str2 << ' ' << str3 << '\n'; return 0;
}

1006 Sign In and Sign Out (25)(25 point(s))的更多相关文章

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

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

  3. MySQL5.7.25(解压版)Windows下详细的安装过程

    大家好,我是浅墨竹染,以下是MySQL5.7.25(解压版)Windows下详细的安装过程 1.首先下载MySQL 推荐去官网上下载MySQL,如果不想找,那么下面就是: Windows32位地址:点 ...

  4. 【PAT】1020 Tree Traversals (25)(25 分)

    1020 Tree Traversals (25)(25 分) Suppose that all the keys in a binary tree are distinct positive int ...

  5. 【PAT】1052 Linked List Sorting (25)(25 分)

    1052 Linked List Sorting (25)(25 分) A linked list consists of a series of structures, which are not ...

  6. 【PAT】1060 Are They Equal (25)(25 分)

    1060 Are They Equal (25)(25 分) If a machine can save only 3 significant digits, the float numbers 12 ...

  7. 【PAT】1032 Sharing (25)(25 分)

    1032 Sharing (25)(25 分) To store English words, one method is to use linked lists and store a word l ...

  8. 【PAT】1015 德才论 (25)(25 分)

    1015 德才论 (25)(25 分) 宋代史学家司马光在<资治通鉴>中有一段著名的“德才论”:“是故才德全尽谓之圣人,才德兼亡谓之愚人,德胜才谓之君子,才胜德谓之小人.凡取人之术,苟不得 ...

  9. 1003 Emergency (25)(25 point(s))

    problem 1003 Emergency (25)(25 point(s)) As an emergency rescue team leader of a city, you are given ...

  10. 1002 A+B for Polynomials (25)(25 point(s))

    problem 1002 A+B for Polynomials (25)(25 point(s)) This time, you are supposed to find A+B where A a ...

随机推荐

  1. 【译】第九篇 Replication:复制监视器

    本篇文章是SQL Server Replication系列的第九篇,详细内容请参考原文. 复制监视器允许你查看复制配置组件的健康状况.这一篇假设你遵循前八篇,并且你已经有一个合并发布和事务发布.启动复 ...

  2. python collection 中的队列

    认识中的队列 在以前的认知里,队列是先进先出,就是一头进,一头出,Queue.而无意间看到了deque 双向队列. 即从该队列的头或者尾部都能插入和移除元素.而起时间复杂度竟然是一样的!O(1),是不 ...

  3. 【多视图几何】TUM 课程 第1章 数学基础:线性代数

    在 YouTube 上找到了慕尼黑工业大学(Technische Universitaet München)计算机视觉组 Daniel Cremers 教授的 Multiple View Geomet ...

  4. HTML 解析 textarea 中的换行符

    用户在textarea中输入的换行符,传到后台,再返回前端,展示在div中. 如果需要div显示为与textarea 一致的效果,需添加: .detail { white-space: pre-lin ...

  5. mvn打war包以及解压包的方法

    有时候我们需要查看打成war包之后的目录,如果是maven项目我们可以直接用maven打包. 1.maven打包: 第一种: mvn package 如果不行先 mvn clean一下 第二种:(掌握 ...

  6. CSS overscroll-behavior

    overscroll-behavior新属性解决了在手机上弹出滚动的一些问题,具体内容查看网址:https://www.w3cplus.com/css/overscroll-behavior.html

  7. 【读书笔记::深入理解linux内核】内存寻址【转】

    转自:http://www.cnblogs.com/likeyiyy/p/3837272.html 我对linux高端内存的错误理解都是从这篇文章得来的,这篇文章里讲的 物理地址 = 逻辑地址 – 0 ...

  8. 原生JS实现AJAX、JSONP及DOM加载完成事件

    一.JS原生Ajax ajax:一种请求数据的方式,不需要刷新整个页面:ajax的技术核心是 XMLHttpRequest 对象:ajax 请求过程:创建 XMLHttpRequest 对象.连接服务 ...

  9. Javascript之对象的创建

    面向对象语言有一个非常显著的标志,那就是它们都有类的概念,通过类之间的继承就可以达到任意创建具有相同属性方法的对象.而在ECMAScript中并没有类的概念,它把对象定义为:无序属性的集合,其属性包含 ...

  10. MAC下安装MAMP后,mysql server无法启动

    用MAC下载安装了MAMP,之前使用是很好没问题的,但是突然无法启动mysql server,检查日志,提示InnDB出错,然后删掉了/Application/MAMP/db/mysql56目录下的i ...