Title Link: http://ac.jobdu.com/problem.php?pid=1013
Detailed Links: https://github.com/zpfbuaa/JobduInCPlusPlus
Reference code:
////1013 Door man and closing man. CPP//Jobdu////Created by Pengfei_zheng on 28/04/2017.//copyright©2017 Pengfei_zheng. All rights reserved.//#include<stdio.h>#include<iostream>#include<algorithm>#include<string.h>#include<cstring>#include<cmath>#defineMax_size 21#defineMax_human 110using namespacestd;intN, M;structsign{CharId[max_size]; intComeh; intComem; intComeS; intlefth; intLEFTM; intlefts;}; intCmpopendoor (Const void*a,Const void*b) { Sign*c = (sign *) A; Sign*d = (sign *) b; if(C->comeh! = d->Comeh) { returnC->comeh-d->Comeh; } Else if(C->comem! = d->Comeh) { returnC->comem-d->Comem; } Else returnC->comes-d->ComeS;} intCmpclosedoor (Const void*a,Const void*b) { Sign*c = (sign *) A; Sign*d = (sign *) b; if(C->lefth! = d->lefth) { returnD->lefth-c->lefth; } Else if(C->LEFTM! = d->LEFTM) { returnD->leftm-c->LEFTM; } Else { returnD->lefts-c->lefts; }} sign Sign[max_human]; intMain () {//freopen ("/users/pengfei_zheng/desktop/input.txt", "R", stdin);scanf"%d",&N); while(n--) {scanf ("%d",&m); for(inti =0; I < m; i++) {scanf ("%s%d:%d:%d%d:%d:%d", SIGN[I].ID,&SIGN[I].COMEH,&SIGN[I].COMEM,&SIGN[I].COMES,&SIGN[I].LEFTH,&SIGN[I].LEFTM, &sign[i].lefts); } qsort (Sign,m,sizeof(sign), Cmpopendoor); printf ("%s", sign[0].id); Qsort (Sign,m,sizeof(sign), Cmpclosedoor); printf ("%s\n", sign[0].id);//for (int i = 0; i < m; i++) {//printf ("%s%d:%d:%d%d:%d:%d\n", Sign[i].id,sign[i].comeh,sign[i].comem,sign[i].comes,sign[i].lefth,sign[i] . leftm,sign[i].lefts);// } }} /************************************************************** problem:1013 User:zpfbuaa language:c++ Re sult:accepted time:0 Ms memory:1524 kb****************************************************************/
Topic 1013: Door opener and closing man (structure custom CMP sort)