• PAT A1006 Sign In and Sign Out


    1006 Sign In and Sign Out

    分数 25

    作者 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. 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:

    1. 3
    2. CS301111 15:30:28 17:00:10
    3. SC3021234 08:00:00 11:25:25
    4. CS301133 21:45:00 21:58:40

    Sample Output:

    SC3021234 CS301133

     

    既然是以时间早晚来输出答案,那肯定得用排序呀,其实不用排序,枚举一遍即可,我这样写还稍显复杂了。

    1. #include <iostream>
    2. #include <string>
    3. #include <algorithm>
    4. #include <vector>
    5. using namespace std;
    6. typedef pair<string, string> PSS;
    7. string transform(string s)
    8. {
    9. string res;
    10. for(int i=0;i<s.size();i+=3)
    11. res += s.substr(i,2);
    12. return res;
    13. }
    14. int main()
    15. {
    16. vector<PSS> In, Out;
    17. int n;
    18. cin >> n;
    19. string id, in, out;
    20. while (n -- )
    21. {
    22. cin >> id >> in >> out;
    23. in = transform(in);
    24. out = transform(out);
    25. In.push_back({in,id});
    26. Out.push_back({out,id});
    27. }
    28. sort(In.begin(), In.end());
    29. sort(Out.begin(), Out.end(), greater<PSS>());
    30. cout << In[0].second << ' ' << Out[0].second << endl;
    31. return 0;
    32. }

  • 相关阅读:
    四、Web开发
    第十一章 JavaScript操作DOM对象
    Django之同时新增数据到两个数据库表与同时返回两个表的数据(插拔式)
    保存文件时电脑提示:你没有权限在此位置中保存文件。请与管理员联系以获得相应权限。
    软件测试工作流程
    一、防火墙-基础知识
    125道Python面试题总结
    2024-Pop!_OS新版本,新桌面环境的消息
    Mysql批量插入数据时如何解决重复问题
    Python避坑指南(续)
  • 原文地址:https://blog.csdn.net/qq_51825761/article/details/127835247