您的位置:首页 > 其它

九度 oj 题目1130:日志排序

2017-01-24 16:07 330 查看
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
)!=0){

sscanf(lines
,"%s %d-%d-%d %d:%d:%d,%d %lf(s)\n",r
.pid,
&r
.date.year,&r
.date.month,&r
.date.day,
&r
.time.hour,&r
.time.minute,&r
.time.sec,&r
.time.mil_sec,
&r
.task_time);
r
.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
.pid,
//r
.date.year,r
.date.month,r
.date.day,
//r
.time.hour,r
.time.minute,r
.time.sec,r
.time.mil_sec,
//r
.task_time);
puts(lines[r[i].id]);
}

}

内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: