题目



输入的部分过长,放在最后

思路

难点主要在输入和输出。。。排序借助malloc new qsort或者sort都可以轻松解决,这个题目特别坑的是给了个“LIST /NAME”这些操作中间还有个空格。。。一下子没发现浪费了好多时间
本人自己写的cmp代码也比较繁琐,下面找了一下其他大佬的cmp代码比鄙人简洁的多,列在改进中

另外,个人理解sort的cmp中返回true是不进行调换
而qsort返回1(true)是调换

改进

代码

#include<iostream>
#include<algorithm>
using namespace std;
class file
{public:int year;int mon;int day;int hour;int min;long long size;string name;};bool Ncmp(const file A ,const file B)
{return (A.name < B.name);
};
bool Scmp(const file A ,const file B)
{if(A.size != B.size){return (A.size < B.size);}else return A.name < B.name;};
bool Tcmp(const file A ,const file B)
{if(A.year < B.year){return true;}else if(A.year > B.year){return false;}else{if(A.mon < B.mon){return true;}else if(A.mon > B.mon){return false;}else{if(A.day < B.day){return true;}else if(A.day > B.day){return false;}else{if(A.hour < B.hour){return true;}else if(A.hour > B.hour){return false;}else{if(A.min < B.min){return true;}else if(A.min > B.min){return false;}else{return(A.name < B.name);}}}}}};void func(int total)
{file* F = new file[total];for(int i = 0; i < total; i++){char c;cin >> F[i].year >> c >> F[i].mon >> c >> F[i].day >> F[i].hour >> c >> F[i].min >> F[i].size >> F[i].name;}string list,opera;//输入的操作有空格。。。cin>>list >> opera;if(opera == "/NAME"){sort(F,F+total,Ncmp);}else if (opera == "/SIZE")//{sort(F,F+total,Scmp);}else if (opera == "/TIME"){sort(F,F+total,Tcmp);}for(int i = 0; i < total; i++){printf("%04d-%02d-%02d %02d:%02d%17lld ",F[i].year,F[i].mon,F[i].day,F[i].hour,F[i].min,F[i].size);\cout << F[i].name << endl;}cout << endl;}int main()
{int total = 1;while(total){   cin >> total;func(total);}return 0;}

输入

5
2011-01-26 07:32 388 ScoreStat.c
2011-01-26 19:48 429 ScoreStat.cpp
2011-01-25 20:11 22016 成绩统计.doc
2011-01-26 19:48 307200 ScoreStat++.exe
2011-01-25 20:08 270336 ScoreStat.exe
LIST /NAME
100
2011-03-11 12:38 0 0.log
2011-03-13 16:34 0 1.txt
2008-06-21 05:55 3680 actsetup.log
2008-06-20 16:40 105 AMS2INST.LOG
2009-06-03 08:10 67 amy.ini
2009-04-01 21:14 66 Cert.INI
2005-08-14 05:00 82944 clock.avi
2008-06-20 14:35 200 cmsetacl.log
2010-02-15 17:21 7640 COM+.log
2010-10-13 11:57 598562 comsetup.log
2008-06-20 14:41 0 control.ini
2009-05-05 09:29 5760054 CoopenOldWallPaper.bmp
2004-08-22 17:04 69120 daemon.dll
2005-08-14 05:00 2 desktop.ini
2008-06-20 15:02 7254 DPINST.LOG
2008-06-20 14:37 133 DtcInstall.log
2007-06-13 21:21 977920 explorer.exe
2008-08-28 11:10 173 explorer.exe.config
2005-08-14 05:00 80 explorer.scf
2010-10-13 11:56 1722100 FaxSetup.log
2005-12-02 11:46 84 filespec7x
2010-02-15 10:15 0 frontpg.ini
2009-09-19 12:11 28 funshionplugin2.INI
2005-05-27 07:22 10752 hh.exe
2008-09-14 08:53 174791 hplj1010.his
2008-09-14 08:53 16734 hplj1010.ini
2008-06-21 05:17 4718 HPQLB.LOG
2011-01-06 08:22 1156 IE4ErrorLog.txt
2008-08-23 10:47 1187 ie7_main.log
2009-06-13 06:34 227494 ie8.log
2009-05-31 11:46 97996 ie8Uninst.log
2009-06-13 06:36 469132 ie8_main.log
2010-10-13 11:57 699472 iis6.log
2010-10-13 11:56 1393 imsins.BAK
2010-10-13 11:57 1393 imsins.log
2009-04-28 12:32 3686454 iSeeLogin.bmp
2009-05-01 21:37 247 iSeeScr.ini
2006-12-18 21:46 926208 iSeeScr.SCR
2010-07-04 10:04 108 iSeeScrView.ini
2003-02-28 16:35 6550 jautoexp.dat
2010-08-11 11:11 14536 KB2079403.log
2010-08-11 10:54 12277 KB2115168.log
2010-09-15 12:05 13816 KB2121546.log
2010-08-11 10:53 14142 KB2160329.log
2010-07-14 09:24 12307 KB2229593.log
2010-10-13 11:56 9405 KB2279986.log
2010-08-04 08:37 15642 KB2286198.log
2010-10-13 11:56 11546 KB2296011.log
2010-09-15 12:06 13163 KB2347290.log
2010-10-13 11:55 9314 KB2360937.log
2010-10-13 11:57 7893 KB2378111.log
2008-06-28 22:19 4664 KB885884.log
2008-06-21 04:43 10587 KB888111.log
2008-06-21 10:11 6354 KB900485.log
2008-06-21 09:11 9628 KB900725.log
2008-06-21 09:12 15952 KB901017.log
2008-06-21 09:12 9284 KB901190.log
2008-06-28 22:21 29878 KB902400.log
2008-06-21 09:11 9224 KB905414.log
2008-06-21 09:11 8737 KB905749.log
2008-06-21 09:12 9661 KB908519.log
2008-06-21 09:13 11978 KB908531.log
2008-06-21 09:12 9574 KB910437.log
2008-06-21 09:14 11227 KB911280.log
2008-06-25 21:42 11718 KB911562.log
2008-06-21 09:13 11904 KB911564.log
2008-06-21 09:12 10071 KB911927.log
2008-06-21 09:13 13500 KB913580.log
2008-06-21 09:14 13607 KB914388.log
2008-06-21 09:13 12478 KB914389.log
2008-06-21 09:13 11170 KB916595.log
2008-10-23 11:27 8334 KB917953.log
2010-02-23 12:01 20716 KB918005.log
2008-06-21 09:17 26131 KB918118.log
2008-06-21 09:14 11554 KB918439.log
2008-06-21 09:16 22589 KB920213.log
2008-06-21 09:14 12660 KB920670.log
2008-06-21 09:14 14402 KB920683.log
2008-06-21 09:14 13456 KB920685.log
2008-06-21 10:11 7966 KB920872.log
2008-06-21 09:15 16750 KB922582.log
2008-06-21 09:15 18878 KB922819.log
2008-06-21 09:16 16837 KB923191.log
2008-06-21 09:15 18684 KB923414.log
2009-04-16 14:54 11335 KB923561.log
2008-06-28 22:20 12345 KB923689.log
2008-06-21 09:16 23117 KB923980.log
2008-06-21 09:16 21088 KB924270.log
2008-06-21 09:15 16660 KB924496.log
2008-06-21 09:17 23957 KB924667.log
2010-02-23 12:03 18315 KB924941.log
2008-06-21 09:16 25353 KB925398.log
2008-06-21 09:17 34802 KB925454.log
2008-06-21 09:15 16070 KB925486.log
2009-09-01 09:55 14919 KB925720.log
2008-06-21 09:19 33141 KB925902.log
2008-06-21 09:17 23030 KB926255.log
2008-06-21 09:18 26224 KB926436.log
2008-06-21 09:18 29889 KB927779.log
2008-06-21 09:18 28576 KB927802.log
LIST /TIME
5
2011-01-26 07:32 388 ScoreStat.c
2011-01-26 19:48 429 ScoreStat.cpp
2011-01-25 20:11 22016 成绩统计.doc
2011-01-26 19:48 307200 ScoreStat++.exe
2011-01-25 20:08 270336 ScoreStat.exe
LIST /TIME
14
2011-03-13 16:32 0 1.txt
2011-01-25 19:17 542 run.bat
2011-03-13 16:29 259 stringSort01.in
2011-03-13 16:29 259 stringSort02.in
2011-03-13 16:29 259 stringSort03.in
2011-03-13 16:29 62 stringSort04.in
2011-03-13 16:30 62 stringSort05.in
2011-03-13 16:30 115 stringSort06.in
2011-01-25 19:36 340 stringSort07.in
2011-01-25 19:38 373 stringSort08.in
2011-01-25 19:39 378 stringSort09.in
2011-01-25 19:40 43 stringSort10.in
2011-01-26 09:15 1103 复件run.bat
2011-03-13 16:31 12 复件复件run.bat
LIST /NAME
5
2011-01-26 07:32 388 ScoreStat.c
2011-01-26 19:48 429 ScoreStat.cpp
2011-01-25 20:11 22016 成绩统计.doc
2011-01-26 19:48 307200 ScoreStat++.exe
2011-01-25 20:08 270336 ScoreStat.exe
LIST /SIZE
100
2011-03-11 12:38 0 0.log
2011-03-13 16:34 0 1.txt
2008-06-21 05:55 3680 actsetup.log
2008-06-20 16:40 105 AMS2INST.LOG
2009-06-03 08:10 67 amy.ini
2009-04-01 21:14 66 Cert.INI
2005-08-14 05:00 82944 clock.avi
2008-06-20 14:35 200 cmsetacl.log
2010-02-15 17:21 7640 COM+.log
2010-10-13 11:57 598562 comsetup.log
2008-06-20 14:41 0 control.ini
2009-05-05 09:29 5760054 CoopenOldWallPaper.bmp
2004-08-22 17:04 69120 daemon.dll
2005-08-14 05:00 2 desktop.ini
2008-06-20 15:02 7254 DPINST.LOG
2008-06-20 14:37 133 DtcInstall.log
2007-06-13 21:21 977920 explorer.exe
2008-08-28 11:10 173 explorer.exe.config
2005-08-14 05:00 80 explorer.scf
2010-10-13 11:56 1722100 FaxSetup.log
2005-12-02 11:46 84 filespec7x
2010-02-15 10:15 0 frontpg.ini
2009-09-19 12:11 28 funshionplugin2.INI
2005-05-27 07:22 10752 hh.exe
2008-09-14 08:53 174791 hplj1010.his
2008-09-14 08:53 16734 hplj1010.ini
2008-06-21 05:17 4718 HPQLB.LOG
2011-01-06 08:22 1156 IE4ErrorLog.txt
2008-08-23 10:47 1187 ie7_main.log
2009-06-13 06:34 227494 ie8.log
2009-05-31 11:46 97996 ie8Uninst.log
2009-06-13 06:36 469132 ie8_main.log
2010-10-13 11:57 699472 iis6.log
2010-10-13 11:56 1393 imsins.BAK
2010-10-13 11:57 1393 imsins.log
2009-04-28 12:32 3686454 iSeeLogin.bmp
2009-05-01 21:37 247 iSeeScr.ini
2006-12-18 21:46 926208 iSeeScr.SCR
2010-07-04 10:04 108 iSeeScrView.ini
2003-02-28 16:35 6550 jautoexp.dat
2010-08-11 11:11 14536 KB2079403.log
2010-08-11 10:54 12277 KB2115168.log
2010-09-15 12:05 13816 KB2121546.log
2010-08-11 10:53 14142 KB2160329.log
2010-07-14 09:24 12307 KB2229593.log
2010-10-13 11:56 9405 KB2279986.log
2010-08-04 08:37 15642 KB2286198.log
2010-10-13 11:56 11546 KB2296011.log
2010-09-15 12:06 13163 KB2347290.log
2010-10-13 11:55 9314 KB2360937.log
2010-10-13 11:57 7893 KB2378111.log
2008-06-28 22:19 4664 KB885884.log
2008-06-21 04:43 10587 KB888111.log
2008-06-21 10:11 6354 KB900485.log
2008-06-21 09:11 9628 KB900725.log
2008-06-21 09:12 15952 KB901017.log
2008-06-21 09:12 9284 KB901190.log
2008-06-28 22:21 29878 KB902400.log
2008-06-21 09:11 9224 KB905414.log
2008-06-21 09:11 8737 KB905749.log
2008-06-21 09:12 9661 KB908519.log
2008-06-21 09:13 11978 KB908531.log
2008-06-21 09:12 9574 KB910437.log
2008-06-21 09:14 11227 KB911280.log
2008-06-25 21:42 11718 KB911562.log
2008-06-21 09:13 11904 KB911564.log
2008-06-21 09:12 10071 KB911927.log
2008-06-21 09:13 13500 KB913580.log
2008-06-21 09:14 13607 KB914388.log
2008-06-21 09:13 12478 KB914389.log
2008-06-21 09:13 11170 KB916595.log
2008-10-23 11:27 8334 KB917953.log
2010-02-23 12:01 20716 KB918005.log
2008-06-21 09:17 26131 KB918118.log
2008-06-21 09:14 11554 KB918439.log
2008-06-21 09:16 22589 KB920213.log
2008-06-21 09:14 12660 KB920670.log
2008-06-21 09:14 14402 KB920683.log
2008-06-21 09:14 13456 KB920685.log
2008-06-21 10:11 7966 KB920872.log
2008-06-21 09:15 16750 KB922582.log
2008-06-21 09:15 18878 KB922819.log
2008-06-21 09:16 16837 KB923191.log
2008-06-21 09:15 18684 KB923414.log
2009-04-16 14:54 11335 KB923561.log
2008-06-28 22:20 12345 KB923689.log
2008-06-21 09:16 23117 KB923980.log
2008-06-21 09:16 21088 KB924270.log
2008-06-21 09:15 16660 KB924496.log
2008-06-21 09:17 23957 KB924667.log
2010-02-23 12:03 18315 KB924941.log
2008-06-21 09:16 25353 KB925398.log
2008-06-21 09:17 34802 KB925454.log
2008-06-21 09:15 16070 KB925486.log
2009-09-01 09:55 14919 KB925720.log
2008-06-21 09:19 33141 KB925902.log
2008-06-21 09:17 23030 KB926255.log
2008-06-21 09:18 26224 KB926436.log
2008-06-21 09:18 29889 KB927779.log
2008-06-21 09:18 28576 KB927802.log
LIST /NAME
1
2011-01-26 07:32 388 ScoreStat.c
LIST /TIME
14
2011-03-13 16:32 0 1.txt
2011-01-25 19:17 542 run.bat
2011-03-13 16:29 259 stringSort01.in
2011-03-13 16:29 259 stringSort02.in
2011-03-13 16:29 259 stringSort03.in
2011-03-13 16:29 62 stringSort04.in
2011-03-13 16:30 62 stringSort05.in
2011-03-13 16:30 115 stringSort06.in
2011-01-25 19:36 340 stringSort07.in
2011-01-25 19:38 373 stringSort08.in
2011-01-25 19:39 378 stringSort09.in
2011-01-25 19:40 43 stringSort10.in
2011-01-26 09:15 1103 复件run.bat
2011-03-13 16:31 12 复件复件run.bat
LIST /TIME
1
2011-01-26 07:32 388 ScoreStat.c
LIST /NAME
2
2011-01-26 19:48 429 ScoreStat.cpp
2011-01-26 19:48 307200 ScoreStat++.exe
LIST /TIME
14
2011-03-13 16:32 0 1.txt
2011-01-25 19:17 542 run.bat
2011-03-13 16:29 259 stringSort01.in
2011-03-13 16:29 259 stringSort02.in
2011-03-13 16:29 259 stringSort03.in
2011-03-13 16:29 62 stringSort04.in
2011-03-13 16:30 62 stringSort05.in
2011-03-13 16:30 115 stringSort06.in
2011-01-25 19:36 340 stringSort07.in
2011-01-25 19:38 373 stringSort08.in
2011-01-25 19:39 378 stringSort09.in
2011-01-25 19:40 43 stringSort10.in
2011-01-26 09:15 1103 复件run.bat
2011-03-13 16:31 12 复件复件run.bat
LIST /NAME
0

课后自主练习(排序)1019. 文件排序 easy《编程思维与实践》个人学习笔记相关推荐

  1. python文件信息排序_python文件排序的方法总结

    在python环境中提供两种排序方案:用库函数sorted()对字符串排序,它的对象是字符:用函数sort()对数字排序,它的对象是数字,如果读取文件的话,需要进行处理(把文件后缀名'屏蔽'). (1 ...

  2. 外部排序——大文件排序

    外部排序 外部排序指的是大文件排序,即待排序的记录存储在外存储器上,待排序的文件无法一次装入内存,需要在内存和外部存储器之间进行多次数据交换,以达到排序整个文件的目的. 一般来说外排序分为两个步骤:预 ...

  3. 课后自主练习(排序)1027. 极坐标排序 easy《编程思维与实践》个人学习笔记

    题目 输入 3 5 1.0 1.0 2.0 2.0 -1.0 1.0 0 1.0 1.0 0 1 0 -1.0 6 1.0 1.0 0 1.0 1.0 0 -1.0 1.0 -1.0 -1.0 1.0 ...

  4. 课后自主练习 (进制)1014. i-1 进制(Easy)naive《编程思维与实践》个人学习笔记

    题目 思路①(比较拉跨的思路) 先转换成十进制再转换成2进制之后按复数相乘若干次相加即可.可惜不能AC只能过部分数据. 麻了--题目给的数据太大LL都放不下,过段时间再写一个用字符串处理的情况吧,,, ...

  5. 【文件包含、宏、条件编译】(学习笔记21--预处理命令)

    目录 文件包含 头文件 #include命令 多文件编译 宏 宏的定义 宏的取消定义 带参宏 将参数转换为字符串常量 参数结合 宏的嵌套使用 转换宏 条件编译 #if命令 #ifdef命令 #ifnd ...

  6. python文件是什么的集合和抽象_python学习笔记(三):文件操作和集合

    这篇博客来说一下python对文件的操作. 对文件的操作分三步: 1.打开文件获取文件的句柄,句柄就理解为这个文件 2.通过文件句柄操作文件 3.关闭文件. 现有以下文件file.txt: 1 2 3 ...

  7. 绕过黑名单检查实现文件上传1 ——合天网安实验室学习笔记

    实验链接 文件上传指将客户端数据以文件形式封装,通过网络协议发送到服务器端.在服务器端解析数据,最终在服务端硬盘上作为真实的文件保存.了解文件上传漏洞产生的原因,掌握漏洞的利用方法. 链接:http: ...

  8. python编程入门贴吧_《Python编程从入门到实践》学习笔记10:文件和异常

    #############################################################################################一些你必须要知 ...

  9. mysql临时文件和临时表_理解mysql的临时表和文件排序

    我们经常看到Mysql的explain语句执行结果Extra字段有using temporary或者using filesort,本文主要是为了理解这两个短语的含义,从而有助于我们进行SQL语句优化. ...

  10. MySQL——Using Filesort文件排序详解

    文章目录 前言 filesort文件排序方式 单路排序或双路排序的选择 trace工具测试单双路排序 文件排序方式选择 前言 在之前,分析SQL索引使用情况时,使用 Explain执行计划参数说明 进 ...

最新文章

  1. uniapp同步获取用户信息_微信小程序云开发教程微信小程序的API入门获取用户身份信息系列API...
  2. C#, ASP.NET面试题系列(1)
  3. 判断两个数组内容是否相同
  4. CNDO-INTGRL-SS-BINTGS-斯莱特轨道指数---递推方法
  5. Nacos客户端注册的流程图
  6. 【POJ - 2909 】Goldbach's Conjecture (哥德巴赫猜想,数论,知识点结论)
  7. 获得OnOK退出控制
  8. 如何删除2345浏览器网络导航主页
  9. 服务器解压文件出错,四大方法解决解压文件出错问题|解压文件出错
  10. 数字化时代,银行如何建设管理小程序平台促进线上金融业务发展?
  11. 【计算机网络】网关和路由器功能的有哪些不同
  12. 2021.5.10-2021.5.16周报
  13. 解密:顺丰是一家什么样的公司
  14. 习题9-3 平面向量加法 (15 分)
  15. flutter学习笔记--传递信息
  16. 软件测试app访问相机,PlayMemories Mobile应用实测,让相机成为你手机的外置摄像头...
  17. SAS学习步骤和参考书
  18. dagger2-重点篇
  19. 【批处理DOS-CMD命令-汇总和小结】-显示文本文件内容(type),对文本文件的整行字符串进行排序(sort)
  20. long数组与Long数组转换

热门文章

  1. turtle库绘图:绘制QQ所有表情
  2. 缠论108课_缠论108课学习顺序
  3. new一个对象的过程中发生了什么?
  4. 【小程序】前端微信授权登录
  5. 航空以太网(ARINC664)接口测试工具
  6. 2004年中国十大暴利行业
  7. 微软资深副总裁洪小文:人工智能十年预测(演讲全文、61PPT)
  8. CMOS门与TTL门
  9. python求主析取范式_python应用之求主析取范式,主合取范式
  10. R语言:作业二(矩阵:求行列式、逆矩阵、特征值、特征向量)【补充:矩阵相关运算知识】