1006 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<cstdio>
#include<cstdlib>
#include<cmath>
#include<vector>
#include<string>
using namespace std;;

struct Person{//员工的信息
    char Name[16];//ID
    int SHour;//进入的时间
    int SMinute;
    int SSecond;
    int EHour;//出去的时间
    int EMunite;
    int ESecond;
}persons[1000];

int StartCmp(Person A,Person B){//进入时间的比较
    if(A.SHour<B.SHour){
        return 1;
    }
    else if(A.SHour>B.SHour){
        return 0;
    }
    else{
        if(A.SMinute<B.SMinute){
            return 1;
        }
        else if(A.SMinute>B.SMinute){
            return 0;
        }
        else{
            if(A.SSecond<B.SSecond){
                return 1;
            }
            else {
                return 0;
            }
        }
    }
}
int EndCmp(Person A,Person B){//出去时间的比较
    if(A.EHour>B.EHour){
        return 1;
    }
    else if(A.EHour<B.EHour){
        return 0;
    }
    else{
        if(A.EMunite>B.EMunite){
            return 1;
        }
        else if(A.EMunite<B.EMunite){
            return 0;
        }
        else {
            if(A.ESecond>B.ESecond){
                return 1;
            }
            else{
                return 0;
            }
        }
    }
}
int FindMaxPerson(Person persons[],int M){//求最晚出去的人在数组中的位置
    if(M==1){
        return 0;
    }
    int MaxNumber=0;
    Person MaxPerson;
    MaxPerson = persons[0];
    for(int i=1;i<M;i++){
        if(EndCmp(persons[i],MaxPerson)){
            MaxPerson = persons[i];
            MaxNumber = i;
        }
    }
    return MaxNumber;
}
int FindMinPerson(Person persons[],int M){//求最早进入的人在数组中的位置
    if(M==1){
        return 0;
    }
    int MinNumber = 0;
    Person MinPerson = persons[0];
    for(int i=1;i<M;i++){
        if(StartCmp(persons[i],MinPerson)){
            MinNumber = i;
            MinPerson = persons[i];
        }
    }
    return MinNumber;
}
int main(){
    int M;
    scanf("%d",&M);
    for(int i = 0;i<M;i++){//每个员工的信息存入数组中
        scanf("%s %d:%d:%d %d:%d:%d",&persons[i].Name,&persons[i].SHour,&persons[i].SMinute,&persons[i].SSecond,
              &persons[i].EHour,&persons[i].EMunite,&persons[i].ESecond);

    }
    int MaxNumber,MinNumber;
    MaxNumber = FindMaxPerson(persons,M);//得到最晚的人
    MinNumber = FindMinPerson(persons,M);//得到最早的人
    printf("%s %s\n",persons[MinNumber].Name,persons[MaxNumber].Name);
}

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值