首页 > 代码库 > 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; }
声明:以上内容来自用户投稿及互联网公开渠道收集整理发布,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任,若内容有误或涉及侵权可进行投诉: 投诉/举报 工作人员会在5个工作日内联系你,一经查实,本站将立刻删除涉嫌侵权内容。