zoukankan      html  css  js  c++  java
  • 1006. Sign In and Sign Out (25)

    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
    




    还是一道很简单的题,但是值得纪念的是第一次提交就全对了!
    用的是map然后重载运算符分别求最大和最小。
    bool operator <(const data t1,const data t2){return ...}





    #include <iostream>
    #include <map>
    #include <string>
    using namespace std;
    
    
    typedef struct data{
      int h,m,s;
    }data;
    
    bool operator<(const data &t1,const data &t2){
    
    return (t1.h<t2.h) || (t1.h==t2.h&&t1.m<t2.m) || (t1.h==t2.h&&t1.m==t2.m&&t1.s<t2.s);
    
    }
    
    
    map<data,string> in;
    map<data,string> out;
    
    data intime[10005];
    data outtime[10005];
    
    int main()
    {
        int n;
        cin>>n;
        int i=0;
        while(n--){
            string Itime,Otime,ID;
            cin>>ID>>Itime>>Otime;
            data I,O;
            I.h=(Itime[0]-48)*10+(Itime[1]-48);
            I.m=(Itime[3]-48)*10+(Itime[4]-48);
            I.s=(Itime[6]-48)*10+(Itime[7]-48);
            O.h=(Otime[0]-48)*10+(Otime[1]-48);
            O.m=(Otime[3]-48)*10+(Otime[4]-48);
            O.s=(Otime[6]-48)*10+(Otime[7]-48);
            in[I]=ID;
            out[O]=ID;
            intime[i]=I;
            outtime[i]=O;
            i++;
        }
        data min;
        min.h=60,min.m=60,min.s=60;
        for(int j=0;j<i;j++){
           if(intime[j]<min){
              min.h=intime[j].h;
              min.m=intime[j].m;
              min.s=intime[j].s;
           }
        }
        cout<<in[min];
        data max;
        max.h=0,max.m=0,max.s=0;
        for(int j=0;j<i;j++){
           if(max<outtime[j]){
              max.h=outtime[j].h;
              max.m=outtime[j].m;
              max.s=outtime[j].s;
           }
        }
        cout<<" "<<out[max];
        return 0;
    }
  • 相关阅读:
    利用Form组件和ajax实现的注册
    基于ajax实现的登录
    【字符串】【kmp模板】
    【字符串入门专题1】 I
    【字符串入门专题1】A
    【最短路入门专题1】H
    【最短路入门专题1】D
    【最短路入门专题1】E
    【最短路径入门专题1】K
    【多校连萌2】D题 ykc想吃好吃的【补题】【最大子段和变形题】
  • 原文地址:https://www.cnblogs.com/Qmelbourne/p/6063544.html
Copyright © 2011-2022 走看看