首页 > 代码库 > 题目1013:开门人和关门人(结构体自定义cmp排序)
题目1013:开门人和关门人(结构体自定义cmp排序)
题目链接:http://ac.jobdu.com/problem.php?pid=1013
详解链接:https://github.com/zpfbuaa/JobduInCPlusPlus
参考代码:
//// 1013 开门人和关门人.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>#define MAX_SIZE 21#define MAX_HUMAN 110 using namespace std; int n, m; struct Sign{ char id[MAX_SIZE]; int comeH; int comeM; int comeS; int leftH; int leftM; int leftS;}; int cmpOpenDoor(const void *a , const void *b){ Sign *c = (Sign *)a; Sign *d = (Sign *)b; if(c->comeH != d->comeH){ return c->comeH - d->comeH; } else if(c->comeM != d->comeH){ return c->comeM - d->comeM; } else return c->comeS - d->comeS;} int cmpCloseDoor(const void *a , const void *b){ Sign *c = (Sign *)a; Sign *d = (Sign *)b; if(c->leftH != d->leftH){ return d->leftH - c->leftH; } else if(c->leftM != d->leftM){ return d->leftM - c->leftM; } else { return d->leftS - c->leftS; }} Sign sign[MAX_HUMAN]; int main(){// freopen("/Users/pengfei_zheng/Desktop/input.txt", "r", stdin); scanf("%d",&n); while(n--){ scanf("%d",&m); for(int i = 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++ Result: Accepted Time:0 ms Memory:1524 kb****************************************************************/
题目1013:开门人和关门人(结构体自定义cmp排序)
声明:以上内容来自用户投稿及互联网公开渠道收集整理发布,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任,若内容有误或涉及侵权可进行投诉: 投诉/举报 工作人员会在5个工作日内联系你,一经查实,本站将立刻删除涉嫌侵权内容。