1006.Sign in and Sign out(25)—PAT 甲级

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

题目大意:在一堆开门关门的员工中,分别找到最早开门和最晚关门的员工号.
分析:利用c++string类型用字典序进行比较的特性直接比较开门时间和关门时间,temp_unlock和temp_lock分别是比较开门时间和关门时间的临时变量,first_unlock和last_lock分别用来记录最早开门和最晚开门的员工号。

#include <iostream>
using namespace std;
int main() {
    string first_unlock,final_lock;
    int m;
    scanf("%d",&m);
    string id_number,unlock,lock;
    string temp_unlock="9",temp_lock="0";
    for(int i=0;i<m;i++)
    {
        cin>>id_number>>unlock>>lock;
        if(unlock<temp_unlock){
            temp_unlock=unlock;
            first_unlock=id_number;
        }
        if(lock>temp_lock){
            temp_lock=lock;
            final_lock=id_number;
        }
    }
    cout<<first_unlock<<" "<<final_lock<<endl;
    return 0;
}

原文地址:https://www.cnblogs.com/Endlessp162096/p/8971944.html

时间: 2024-07-28 16:55:38

1006.Sign in and Sign out(25)—PAT 甲级的相关文章

1020. Tree Traversals (25) PAT甲级真题

之前我看了这道题,实在是看不懂网上的解题答案,他们的具体思路基本上就是通过后续遍历和中序遍历,直接推出层次遍历. 我苦思冥想了半天,是在没看懂这种思路,于是想了一个笨点的但是也比较好理解的思路,通过后续和中序,先推出整个二叉树,再考虑 对二叉树层次遍历. 本题还有一点要注意的时在输出结果的末尾,如果使用了类似 pirntf("%d ",data); 这样的格式是不对的,一定要对末尾进行判断消除最尾端的空格. 首先最核心的部分是通过两次遍历反推回二叉树:这里的思路是,后续遍历的最末尾,一

1078. Hashing (25)-PAT甲级真题

1078. Hashing (25)The task of this problem is simple: insert a sequence of distinct positive integers into a hash table, and output the positions of the input numbers. The hash function is defined to be "H(key) = key % TSize" where TSize is the

1085. Perfect Sequence (25)-PAT甲级真题

1085. Perfect Sequence (25) 时间限制 300 ms 内存限制 65536 kB 代码长度限制 16000 B 判题程序 Standard 作者 CAO, Peng Given a sequence of positive integers and another positive integer p. The sequence is said to be a "perfect sequence" if M <= m * p where M and m

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

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

题目信息: 1006. Sign In and Sign Out (25) 时间限制 400 ms 内存限制 32000 kB 代码长度限制 16000 B 判题程序 Standard 作者 CHEN, Yue 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 th

pat1006. Sign In and Sign Out (25)

1006. Sign In and Sign Out (25) 时间限制 400 ms 内存限制 65536 kB 代码长度限制 16000 B 判题程序 Standard 作者 CHEN, Yue 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

PAT 甲级 A1082 (2019/02/14) NULL(12/25)

1 #include<cstdio> 2 #include<cstring> 3 char strnumber[16][5] = {"ling", "yi", "er", "san", "si", "wu", "liu", "qi", "ba", "jiu", "Ge&quo

【PAT甲级】1070 Mooncake (25 分)(贪心水中水)

题意: 输入两个正整数N和M(存疑M是否为整数,N<=1000,M<=500)表示月饼的种数和市场对于月饼的最大需求,接着输入N个正整数表示某种月饼的库存,再输入N个正数表示某种月饼库存全部出手的利润.输出最大利润. trick: 测试点2可能包含M不为整数的数据.(尽管题面说明M是正整数,可是根据从前PAT甲级题目的经验,有可能不是整数.....) 代码: #define HAVE_STRUCT_TIMESPEC#include<bits/stdc++.h>using names

PAT甲级第二次真题练习

1005 Spell It Right (20)(20 分)提问 Given a non-negative integer N, your task is to compute the sum of all the digits of N, and output every digit of the sum in English. Input Specification: Each input file contains one test case. Each case occupies one

PAT甲级1005 Spell It Right

题目:PAT甲级 1005 题解:水题.看到题目的第一时间就在想一位一位的mod,最后一加一转换就完事了.结果看到了N最大为10的100的次方,吓得我赶紧放弃这个想法... 发现碰到这种情况用字符串十分好用,这道题应该考察的就是这一点.大致思路就是把数字的每一位放到字符串中,然后通过ASCII码得到每一位的相加结果num,然后把num一位一位的放到stack中,使用stack是因为它先进先出的特性,最后输出就行了. 代码: 1 #include<cstdio> 2 #include<qu