码迷,mamicode.com
首页 > 编程语言 > 详细

题目1013:开门人和关门人(结构体自定义cmp排序)

时间:2017-05-13 00:01:08      阅读:301      评论:0      收藏:0      [点我收藏+]

标签:des   users   题目   accept   ble   txt   desktop   span   reserve   

题目链接: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排序)

标签:des   users   题目   accept   ble   txt   desktop   span   reserve   

原文地址:http://www.cnblogs.com/zpfbuaa/p/6847645.html

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