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

  • 相关阅读:
    C语言【文件】
    一阶段Linux整理
    SVN使用总结
    unity自动寻路
    Elasticsearch&JDK版本要求
    OpenGL ES EGL 名词解释
    Java并发编程—CompletableFuture的异步执行案例
    swiper动态渲染视图,解决答题问题
    一文掌握SSD、EMMC、UFS原理与差异
    物联网IOT 固件升级
  • 原文地址:https://blog.csdn.net/qq_51825761/article/details/127835247