九度 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]);
}
}
参考了 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]);
}
}
相关文章推荐
- 九度OJ 题目1130:日志排序
- 九度OJ 题目1130:日志排序
- 【九度】题目1130:日志排序
- 九度 OJ 之 题目1202:排序
- 九度oj 题目1066:字符串排序
- 【九度OJ】题目1202:排序 解题报告
- 九度OJ 题目17:所有员工年龄排序
- 题目1185:特殊排序 九度OJ
- 【九度OJ】题目1061:成绩排序 解题报告
- 题目1130:日志排序
- 九度oj 题目1007:奥运排序问题 【ZJU2010考研机试题3】【容易理解混乱】
- 【九度OJ】题目1202:排序 解题报告
- 【九度OJ】题目1185:特殊排序 解题报告
- 题目1130:日志排序
- 九度oj 题目1023:EXCEL排序
- 【九度OJ】题目1054:字符串内排序 解题报告
- 九度OJ 题目1023:EXCEL排序
- 【九度OJ】题目1061:成绩排序
- [九度oj]题目1349:数字在排序数组中出现的次数
- OJ_1130 日志排序