PAT-A 1006. Sign In and Sign Out (25)

题目链接在此。

题意

求最早、最晚到的人。

思路

结合下面的代码,参考这题思路。

AC代码

#include
#include

int main(){

    char unlock[16], lock[16], temp[16];
    int M;
    int hh1,mm1,ss1,hh2,mm2,ss2;
    long long time1,time2;
    long long earliest = 246060, lastest = 000000;

    scanf("%d",&M);
    for(int i = 0; i < M; i++){
        scanf("%s %d:%d:%d %d:%d:%d",&temp,&hh1,&mm1,&ss1,&hh2,&mm2,&ss2);
        time1 = hh1*10000+mm1*100+ss1;
        time2 = hh2*10000+mm2*100+ss2;
        if(time1 < earliest){
            earliest = time1;
            strcpy(unlock,temp);
        }
        if(time2 > lastest){
            lastest = time2;
            strcpy(lock,temp);
        }
    }

    printf("%s %s\n",unlock,lock);

    return 0;
} 

你可能感兴趣的:(ll型时间比较法,PAT-A,PAT甲级,PAT-A-1006,C语言,PAT,(Advanced,Level),Practise)