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

    1006 Sign In and Sign Out (25)(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


    每天有 M 个人进入计算机室 给出人的 ID , 进入计算机室的时间 和 离开计算机室的时间
    输出每天第一个进入实验室开门和最后一个离开实验室关门的人的ID


    #include <iostream>
    #include <cstdio>
    #include <algorithm>
    #include <cstring>
    #include <string>
    
    using namespace std ; 
    
    struct node {
        char ID[20] ; 
        int startH,
            startM,
            startS;
        int endH,
            endM,
            endS;
    };
    
    #define maxn 10000
    node peoper[maxn] ; 
    int n ; 
    
    // sort : start time
    bool cmp1(node a, node b){
        if(a.startH < b.startH){
            return true ; 
        }else if((a.startH == b.startH) && (a.startM < b.startM)){
            return true ; 
        }else if((a.startH == b.startH) && (a.startM == b.startM) && (a.startS < b.startS)){
            return true ; 
        }
        return false ; 
    }
    
    // sort : end time
    bool cmp2(node a , node b){
        if(a.endH > b.endH){
            return true ; 
        }else if((a.endH == b.endH) && (a.endM > b.endM)){
            return true ; 
        }else if((a.endH == b.endH) && (a.endM == b.endM) && (a.endS > b.endS)){
            return  true ; 
        }
        return false ; 
    }
    
    int main(){
    
        while(cin >> n){
    
            for(int i=0 ; i<n ; i++){
                //     ID
                cin >> peoper[i].ID ; 
                //    Sign in time
                scanf("%d:%d:%d", &peoper[i].startH, &peoper[i].startM, &peoper[i].startS) ; 
                //    Sign Out time
                scanf("%d:%d:%d", &peoper[i].endH, &peoper[i].endM, &peoper[i].endS);
            }
    
            char ID1[20], ID2[20] ; 
    
            sort(peoper, peoper + n , cmp1) ; 
            strcpy(ID1, peoper[0].ID) ; 
    
            sort(peoper, peoper + n , cmp2) ; 
            strcpy(ID2, peoper[0].ID) ; 
    
            cout << ID1 << " " << ID2 << endl ; 
        }
        return 0 ; 
    }
  • 相关阅读:
    常用开发技巧系列(三)
    快速排序OC、Swift版源码
    一步一步学习SignalR进行实时通信_8_案例2
    一步一步学习SignalR进行实时通信_7_非代理
    一步一步学习SignalR进行实时通信_6_案例
    一步一步学习SignalR进行实时通信_5_Hub
    一步一步学习SignalR进行实时通信_4_Hub
    一步一步学习SignalR进行实时通信_3_通过CORS解决跨域
    一步一步学习SignalR进行实时通信_2_Persistent Connections
    一步一步学习SignalR进行实时通信_1_简单介绍
  • 原文地址:https://www.cnblogs.com/yi-ye-zhi-qiu/p/9508908.html
Copyright © 2011-2022 走看看