首页 > 代码库 > hdu 开门人和关门人

hdu 开门人和关门人

/*
* hdu OpenDoorManAndCloseDoorMan
* date 2014/5/13
* state AC
*/
#include <iostream>
#include <fstream>
#include <algorithm>
#include <vector>

using namespace std;

struct DoorMan
{
    char name[20];
    int startH,startM,startS;
    int endH,endM,endS;
};

vector<DoorMan> vectorDoorMan;

bool CompStartTime(const DoorMan& a,const DoorMan& b)
{
    if(a.startH!=b.startH)return a.startH<b.startH;
    else if(a.startH == b.startH && a.startM!=b.startM)
    {
        return a.startM<b.startM;
    }
    else if(a.startH == b.startH && a.startM == b.startM && a.startS !=b.startS)
        return a.startS<b.startS;
}

bool CompEndTime(const DoorMan& a,const DoorMan& b)
{
    /*
    if(a.endH!=b.endH)return a.endH>b.endH;
    else if(a.endH==b.endH && a.endM!=b.endM)
        return a.endM>b.endM;
    else if(a.endH==b.endH && a.endM==b.endM && a.endS!=b.endS)
        return a.endS>b.endS;
    */
    if(a.endH!=b.endH)return a.endH>b.endH;
    else if(a.endM!=b.endM) return a.endM>b.endM;
    else if(a.endS!=b.endS) return a.endS>b.endS;
}

int main()
{
    //cout << "Hello world!" << endl;
    freopen("input.txt","r",stdin);
    int N;
    cin>>N;
    for(int i=0;i<N;i++)
    {
        vectorDoorMan.clear();
        int M;
        cin>>M;
        for(int j=0;j<M;j++)
        {
            //char strName[20];
            //int startH,startM,startS;
            //int endH,endM,endS;
            DoorMan doorMan;
            scanf("%s %d:%d:%d %d:%d:%d",doorMan.name,&doorMan.startH,&doorMan.startM,&doorMan.startS
                  ,&doorMan.endH,&doorMan.endM,&doorMan.endS);
            vectorDoorMan.push_back(doorMan);
        }
        sort(vectorDoorMan.begin(),vectorDoorMan.end(),CompStartTime);
        //cout<<endl;
        DoorMan openDoorMan=vectorDoorMan[0];
        sort(vectorDoorMan.begin(),vectorDoorMan.end(),CompEndTime);
        DoorMan closeDoorMan=vectorDoorMan[0];

        //cout<<openDoorMan.name<<" "<<openDoorMan.startH<<":"<<openDoorMan.startM<<":"<<openDoorMan.startS<<" ";
        //cout<<closeDoorMan.name<<" "<<closeDoorMan.endH<<":"<<closeDoorMan.endM<<":"<<closeDoorMan.endS;
        cout<<openDoorMan.name<<" "<<closeDoorMan.name;
        cout<<endl;
    }
    return 0;
}