• 题目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
    ",sign[0].id);
    //        for(int i = 0 ; i < m ; i++){
    //            printf("%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);
    //        }
        }
    }
     
     
     
     
    /**************************************************************
        Problem: 1013
        User: zpfbuaa
        Language: C++
        Result: Accepted
        Time:0 ms
        Memory:1524 kb
    ****************************************************************/
  • 相关阅读:
    Could not transfer artifact org.apache.maven.plugins:maven-resources-plugin:pom:2.6 from/to central
    SpringMVC详解
    数据库连接池
    事务的隔离级别
    数据库四大特性
    Eclipse自动编码提示设置
    RequestDispatcher.forward转发与HttpServletResponse.sendRedirect重定向
    c#代码混淆
    java反射机制
    (转)redis是什么
  • 原文地址:https://www.cnblogs.com/zpfbuaa/p/6847645.html
Copyright © 2020-2023  润新知