题目1130:日志排序
来源:互联网 发布:青岛seo服务 编辑:程序博客网 时间:2024/05/15 13:33
#include<stdio.h>#include<string.h>#include<stdlib.h> typedef struct node{ char name[15]; char tt[20],ttime[15],tle[20]; int year; int month; int day; int times; int length; int k1,k2,k3,k4;}NODE; int cmp(const void *a,const void *b){ int ay=(*(NODE *)a).year,by=(*(NODE *)b).year; int am=(*(NODE *)a).month,bm=(*(NODE *)b).month; int ad=(*(NODE *)a).day,bd=(*(NODE *)b).day; int at=(*(NODE *)a).times,bt=(*(NODE *)b).times; int ale=(*(NODE *)a).length,ble=(*(NODE *)b).length; if(ale!=ble) return ale-ble; else if(ay!=by) return ay-by; else if(am!=bm) return am>bm?1:-1; else if(ad!=bd) return ad-bd; else return at-bt;} int main(){ NODE record[10005]; int k=0; char tempn[15],temptime[20],temptime2[15],temple[20],temp[1000]; while(gets(temp)) { memset(tempn, 0, sizeof(tempn)); memset(temptime, 0, sizeof(temptime)); memset(temptime2, 0, sizeof(temptime2)); memset(temple, 0, sizeof(temple)); int zhizhen=0; record[k].year=record[k].month=record[k].day=record[k].times=record[k].length=record[k].k1=0; record[k].k2=record[k].k3=record[k].k4=0; int i; int llllll=strlen(temp); if(llllll==0) break; for(i=0;i<llllll;i++) { if(temp[i]!=' ') break; else record[k].k1++; } for(;i<llllll;i++) { if(temp[i]==' ') break; else tempn[zhizhen++]=temp[i]; } for(;i<llllll;i++) { if(temp[i]!=' ') break; else record[k].k2++; } zhizhen=0; for(;i<llllll;i++) { if(temp[i]==' ') break; else temptime[zhizhen++]=temp[i]; } i++; zhizhen=0; for(;i<llllll;i++) { if(temp[i]==' ') break; else temptime2[zhizhen++]=temp[i]; } for(;i<llllll;i++) { if(temp[i]!=' ') break; else record[k].k3++; } zhizhen=0; for(;i<llllll;i++) { if(temp[i]==' ') break; else temple[zhizhen++]=temp[i]; } for(;i<llllll;i++) record[k].k4++; strcpy(record[k].name, tempn); strcpy(record[k].tt, temptime); strcpy(record[k].ttime, temptime2); strcpy(record[k].tle, temple); for(i=0;i<4;i++) record[k].year=record[k].year*10+(int)temptime[i]-48; for(i=5;i<7;i++) record[k].month=record[k].month*10+(int)temptime[i]-48; for(i=8;i<10;i++) record[k].day=record[k].day*10+(int)temptime[i]-48; int h=0,min=0,se=0,hse=0; h=((int)temptime2[0]-48)*10+(int)temptime2[1]-48; min=((int)temptime2[3]-48)*10+(int)temptime2[4]-48; se=((int)temptime2[6]-48)*10+(int)temptime2[7]-48; hse=((int)temptime2[9]-48)*100+((int)temptime2[10]-48)*10+(int)temptime2[11]-48; record[k].times=(h*3600+min*60+se)*1000+hse; int a=0,b=0; for(i=0;temple[i]!='.';i++) a=a*10+(int)temple[i]-48; i++; for(;temple[i]!='(';i++) b=b*10+(int)temple[i]-48; record[k].length=a*1000+b; k++; } qsort(record, k, sizeof(record[0]), cmp); int i; for(i=0;i<k;i++) { int j; for(j=0;j<record[i].k1;j++) printf(" "); printf("%s",record[i].name); for(j=0;j<record[i].k2;j++) printf(" "); printf("%s %s",record[i].tt,record[i].ttime); for(j=0;j<record[i].k3;j++) printf(" "); printf("%s",record[i].tle); for(j=0;j<record[i].k4;j++) printf(" "); printf("\n"); } return 0;}/************************************************************** Problem: 1130 User: cust123 Language: C++ Result: Accepted Time:30 ms Memory:2168 kb****************************************************************/
0 0
- 题目1130:日志排序
- 题目1130:日志排序
- 题目1130:日志排序
- 题目1130:日志排序
- 九度OJ 题目1130:日志排序
- 【九度】题目1130:日志排序
- 九度OJ 题目1130:日志排序
- 九度OJ 题目1130:日志排序
- 九度 oj 题目1130:日志排序
- 九度OJ 1130:日志排序 (排序)
- 题目:283 对称排序
- 题目1:排序
- 题目2:成绩排序
- 题目3:特殊排序
- 题目4:EXCEL排序
- 题目1167:数组排序
- 题目1:排序
- 题目1066:字符串排序
- 分类游戏
- unit13
- JAVA静态上下文引用问题
- Centos7搭建代理服务器Shadowsocks
- Eclipse在线安装Drools插件
- 题目1130:日志排序
- 判断获取的数据是不是number类型
- Volley框架请求取消的实现
- Rp-800旧版废弃代码的研究文档
- 人月神话之四 贯彻执行、为什么巴比伦塔会失败
- 用A*算法解决八数码问题 MATLAB
- Android学习之AlarmManager使用
- Android 构建的新欢Gradle
- 河南省第九届ACM程序设计竞赛。问题 F: Decimal integer conversion