A1006 Sign In and Sign Out

#include<stdio.h>
#include<string.h>

/*
思路:
    1.创建结构性变量pNode,内部成员为id和时间;
    2.创建比较函数great(a,b),a的时间>b的时间话返回true; 
    3.输入时,把签到时间和签退时间分开录入,录入签到时间时,利用比较函数great()来获得答案; 

*/ 


using namespace std;

struct pNode{
    char id[16];
    int hh,mm,ss;
}temp,ans1,ans2;    //ans1保存答案1,ans2保存答案2 

bool great(pNode a,pNode b){    //a的时间大于b的时间返回true 
    if(a.hh != b.hh) return a.hh>b.hh;
    if(a.mm != b.hh) return a.mm>b.mm;
    return a.ss >=b.ss;

} 

int main(){

    int n;
    scanf("%d",&n);

    ans1.hh = 24;    ans1.mm = 60;    ans1.ss = 60;    //初始化签到时间为最大值 
    ans2.hh = 0;    ans2.mm = 0;    ans2.ss = 0;    //初始化签退时间为最小值 

    for(int i=0;i<n;i++){
        scanf("%s %d:%d:%d",temp.id,&temp.hh,&temp.mm,&temp.ss);

        if(great(ans1,temp))    ans1 = temp;

        scanf("%d:%d:%d",&temp.hh,&temp.mm,&temp.ss);

        if(great(temp,ans2))    ans2 = temp;
    }

    printf("%s %s",ans1.id,ans2.id);


    return 0;
}
全部评论

相关推荐

头顶尖尖的程序员:我是26届的不太懂,25届不应该是找的正式工作吗?为什么还在找实习?大四还实习的话是为了能转正的的岗位吗
点赞 评论 收藏
分享
废物一个0offer:认真的吗二本本科找人工智能岗位
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

更多
牛客网
牛客网在线编程
牛客网题解
牛客企业服务