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;
    }
  • 相关阅读:
    .net通用签名方法 webapi签名方法
    实体类的[Serializable]标签造成WebAPI Post接收不到值
    html5获取位置信息,h5获取位置信息
    C#采集:图灵机器人信息
    virtualbox压缩虚拟机硬盘文件vhd
    WinFrom控件双向绑定
    ILMerge合并多个DLL
    在Windows Server 2012 R2的Hyper-V中设置虚拟机启用增强会话模式
    (转)✈工欲善其事,必先利其器✔™
    .NET使用ZXing.NET生成中间带图片的二维码
  • 原文地址:https://www.cnblogs.com/stormax/p/10939724.html
Copyright © 2011-2022 走看看