zoukankan      html  css  js  c++  java
  • pat 1005 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


    #include <iostream>
    #include <string>
    #include <algorithm>
    using namespace std;
    struct customer
    {
        string name;
        int sh, sm, ss;
        int eh, em, es;
    };
    bool cmp1(const customer &c1, const customer &c2)
    {
        if (c1.sh == c2.sh)
        {
            if (c1.sm == c2.sm)
            {
                return c1.ss < c2.ss;
            }
            else
            {
                return c1.sm < c2.sm;
            }
        }
        else
        {
            return c1.sh < c2.sh;
        }
    }
    bool cmp2(const customer &c1, const customer &c2)
    {
        if (c1.eh == c2.eh)
        {
            if (c1.em == c2.em)
            {
                return c1.es > c2.es;
            }
            else
            {
                return c1.em > c2.em;
            }
        }
        else
        {
            return c1.eh > c2.eh;
        }
    }
    int main()
    {
        int m;
        cin >> m;
        string st, et;
        customer cus[1000];
        for (int i = 0; i < m; i++)
        {
            cin >> cus[i].name >> st >> et;
            cus[i].sh = (st[0] - '0') * 10 + st[1] - '0';
            cus[i].sm = (st[3] - '0') * 10 + st[4] - '0';
            cus[i].ss = (st[6] - '0') * 10 + st[7] - '0';
            cus[i].eh = (et[0] - '0') * 10 + et[1] - '0';
            cus[i].em = (et[3] - '0') * 10 + et[4] - '0';
            cus[i].es = (et[6] - '0') * 10 + et[7] - '0';
        }
        sort(cus,cus + m, cmp1);
        cout << cus[0].name << " ";
        sort(cus,cus + m, cmp2);
        cout << cus[0].name;
        return 0;
    }
  • 相关阅读:
    Access restriction on class due to restriction on required library rt.jar?
    Why “no projects found to import”?
    MySQL
    您对无法重新创建的表进行了更改或者启用了“阻止保存要求重新创建表的更改”选项
    INTJINTJ——内向+直觉+思维+判
    豆瓣网案例分析报告
    如何使用Git
    如何在不到六个月的时间内成为一个开发者
    关于网站编程Alex
    string
  • 原文地址:https://www.cnblogs.com/stormax/p/10939724.html
Copyright © 2011-2022 走看看