PAT-Sign In and Sign Out (25)

来源:互联网 发布:c语言下载官方下载 编辑:程序博客网 时间:2024/05/19 23:15

题意:

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

#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;
}

0 0
原创粉丝点击