PAT-Sign In and Sign Out (25)

34 篇文章 0 订阅

题意:

输出最早进来的和最晚进来的人

#include <iostream>
#include <stdio.h>
#include <cstring>
using namespace std;
char a[20];
char b[20];
char c[20];
int main()
{
    int maxh,maxf,maxm;
    int minh,minf,minm;
    int n;
    cin>>n;
    int tep1,tep2,tep3;
    scanf("%s",c);
    strcpy(a,c);
    strcpy(b,c);
    scanf("%d:%d:%d",&tep1,&tep2,&tep3);
    minh=tep1,minf=tep2,minm=tep3;
    scanf("%d:%d:%d",&tep1,&tep2,&tep3);
    maxh=tep1,maxf=tep2,maxm=tep3;
    n--;
    while(n--)
    {
        scanf("%s",c);
        scanf("%d:%d:%d",&tep1,&tep2,&tep3);
        if(tep1<minh)
        {
            strcpy(a,c);
            minh=tep1;
            minf=tep2;
            minm=tep3;
        }
        else if(tep1==minh)
        {
            if(tep2<minf)
            {
                strcpy(a,c);
                minh=tep1;
                minf=tep2;
                minm=tep3;
            }
            else if(tep2==minf)
                if(tep3<minf)
                {
                    strcpy(a,c);
                    minh=tep1;
                    minf=tep2;
                    minm=tep3;
                }
        }
        scanf("%d:%d:%d",&tep1,&tep2,&tep3);
        if(tep1>maxh)
        {
            strcpy(b,c);
            maxh=tep1;
            maxf=tep2;
            maxm=tep3;
        }
        else if(tep1==maxh)
        {
            if(tep2>maxf)
            {
                strcpy(b,c);
                maxh=tep1;
                maxf=tep2;
                maxm=tep3;
            }
            else if(tep2==maxf)
                if(tep3>maxf)
                {
                    strcpy(b,c);
                    maxh=tep1;
                    maxf=tep2;
                    maxm=tep3;
                }
        }


    }
    printf("%s %s",a,b);
    return 0;
}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值