码迷,mamicode.com
首页 > 其他好文 > 详细

hdu 开门人和关门人

时间:2014-05-14 14:58:40      阅读:247      评论:0      收藏:0      [点我收藏+]

标签:algorithm

/*
* 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;
}

hdu 开门人和关门人,布布扣,bubuko.com

hdu 开门人和关门人

标签:algorithm

原文地址:http://blog.csdn.net/greenapple_shan/article/details/25702937

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!