PAT--1006 Sign In and Sign Out

#include <iostream>
#include <string>
#include <stdio.h>
#define MAX 25
#define MIN -1

using namespace std;

struct Node
{
    int h, m, s;
};


int main()
{
    int n;
    string str, str_in, str_out;
    Node time[2];
    scanf("%d", &n);
    int he,me,se,hl,ml,sl;
    he = me = se = MAX;
    hl = ml = sl = MIN;
    while(n--)
    {
        cin >> str;
        scanf("%d:%d:%d", &time[0].h, &time[0].m, &time[0].s);
        scanf("%d:%d:%d", &time[1].h, &time[1].m, &time[1].s);
        if(time[0].h < he)
        {
             str_in = str;
             he = time[0].h;
        }

        else if(time[0].h == he)
        {
            if(time[0].m < me)
            {
                str_in = str;
                me = time[0].m;
            }
            else if(time[0].m == me)
                if(time[0].s < se)
                {
                    str_in = str;
                    se = time[0].s;
                }

        }
        if(time[1].h > hl)
        {
            str_out = str;
            hl = time[1].h;
        }
        else if(time[1].h == hl)
        {
            if(time[1].m < ml)
            {
                str_out = str;
                ml = time[1].m;
            }
            else if(time[1].m == ml)
                if(time[1].s < sl)
                {
                    str_out = str;
                    sl = time[1].s;
                }

        }
    }
    cout << str_in << " " << str_out << endl;

    return 0;
}

猜你喜欢

转载自blog.csdn.net/mch2869253130/article/details/88073769