九度 oj 题目1130:日志排序

62 篇文章 0 订阅
15 篇文章 0 订阅

http://ac.jobdu.com/problem.php?pid=1130


参考了 http://www.cnblogs.com/jasonJie/p/5740646.html


#include <stdio.h>
#include <cmath>
#include <algorithm>

typedef struct date{ 
    int year,month,day; 
    friend bool operator < (struct date a, struct date b){ 
        if(a.year != b.year){ 
            return a.year < b.year; 
        }else if(a.month != b.month){ 
            return a.month < b.month; 
        }else{ 
            return a.day < b.day; 
        }        
    }  
    friend bool operator != (struct date a, struct date b ){ 
        return !(a.year == b.year && a.month == b.month && a.day == b.day); 
    } 
}Date; 

typedef struct time{ 
    int hour,minute,sec,mil_sec; 
    bool friend operator != (struct time a, struct time b){ 
        return !(a.hour == b.hour && a.minute == b.minute 
            && a.sec == b.sec && a.mil_sec == b.mil_sec); 
    } 
    bool friend operator < (struct time a, struct time b){ 
        if(a.hour != b.hour){ 
            return a.hour < b.hour; 
        }else if(a.minute != b.minute){ 
            return a.minute < b.minute; 
        }else if(a.sec != b.sec) { 
            return a.sec < b.sec; 
        }else{ 
            return a.mil_sec < b.mil_sec; 
        }       
    }  
}Time; 

typedef struct record{ 
    int id;
    char pid[11];
    Date date; 
    Time time;
    double task_time;
    bool friend operator < (struct record a, struct record b){ 
        if(fabs(a.task_time - b.task_time)>1e-5 ){ 
            return a.task_time < b.task_time; 
        }else if(a.date != b.date){ 
            return a.date < b.date; 
        }else{ 
            return a.time < b.time; 
        }    
    }  
}Record; 

int main(){ 
    //freopen("in/1130.in","r",stdin); 
    Record r[10001]; 
    char lines[10001][320];
    int n=0;
    while(gets(lines[n])!=0){ 

        sscanf(lines[n],"%s %d-%d-%d %d:%d:%d,%d %lf(s)\n",r[n].pid,
                &r[n].date.year,&r[n].date.month,&r[n].date.day,
                &r[n].time.hour,&r[n].time.minute,&r[n].time.sec,&r[n].time.mil_sec,
                &r[n].task_time);  
        r[n].id = n;

        n++;
    }  
    std::sort(r,r+n);
    for (int i = 0; i < n; ++i) { 
        //printf("%s %d-%d-%d %d:%d:%d,%d %lf(s)\n",r[n].pid,
                //r[n].date.year,r[n].date.month,r[n].date.day,
                //r[n].time.hour,r[n].time.minute,r[n].time.sec,r[n].time.mil_sec,
                //r[n].task_time); 
        puts(lines[r[i].id]);
    } 

}  



  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值