• 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;
    }
  • 相关阅读:
    数据可视化之 图表篇(七)柱形图
    数据可视化之 图表篇(六)桑基图
    数据可视化之 图表篇(五) PowerBI图表不够炫酷?来看看这个
    数据可视化之 图表篇(四) 那些精美的Power BI可视化图表
    数据可视化之 图表篇(三)体验Power BI最新发布的AI图表:分解树
    数据可视化之 图表篇(二)如何用Power BI制作疫情地图?
    数据可视化之 图表篇(一)Power BI可视化,几张图表认识疫情现状
    MCMC随机采样
    Linux中的计划作业
    Linux进程
  • 原文地址:https://www.cnblogs.com/stormax/p/10939724.html
Copyright © 2020-2023  润新知