HNUST 1395日期排序 sort函数 快速排序
2017-03-02 11:04
169 查看
1395: 日期排序
时间限制: 1 Sec 内存限制: 128 MB提交: 157 解决: 104
[提交][状态][讨论版]
题目描述
有一些日期,日期格式为“MM/DD/YYYY”。编程将其按日期大小排列。输入
输出
样例输入
15/12/1999 10/21/2003 10/22/2003 02/12/2004 11/30/2005 12/31/2005
样例输出
15/12/1999 10/21/2003 10/22/2003 02/12/2004 11/30/2005 12/31/2005
#include <iostream> #include<algorithm> #include<cstdio> #include<cstdlib> using namespace std; struct node { int year; int month; int day; }stu[1000]; bool cmp(node x,node y) { if(x.year!=y.year) return x.year<y.year; else if(x.month!=y.month) return x.month<y.month; else return x.day<y.day; } //定义结构体排序规则,默认为从低到高 int main() { int i=0; //freopen("e://in.txt","r",stdin); while(scanf("%d/%d/%d",&stu[i].day,&stu[i].month,&stu[i].year)!=EOF) { i++; } sort(stu,stu+i,cmp); for(int j=0;j<i;j++) printf("%02d/%02d/%d\n",stu[j].day,stu[j].month,stu[j].year); return 0; }//sort函数十分便捷,耗时较少
相关文章推荐
- HNUST 1395日期排序 sort函数 快速排序
- HNUST 1395日期排序 sort函数 快速排序
- HNUST 1395日期排序 sort函数 快速排序
- HNUST 1395日期排序 sort函数 快速排序
- HNUST 1395日期排序 sort函数 快速排序
- HNUST 1395日期排序 sort函数 快速排序
- STL sort 函数实现详解 作者:fengcc 原创作品 转载请注明出处 前几天阿里电话一面,被问到STL中sort函数的实现。以前没有仔细探究过,听人说是快速排序,于是回答说用快速排序实现的
- 排序算法----交换排序(冒泡排序,快速排序)
- 每天学习算法系列—内部排序之归并排序和快速排序
- 数据结构与算法——冒泡排序、选择排序和快速排序
- Python的排序方法:list.sort函数和sorted函数
- 选择排序和快速排序性能比较
- 日期排序
- 数据结构之排序2(快速排序及其优化)
- Java实现数据排序(冒泡、选择、插入、快速排序)---方法持续更新中
- 关于birt交叉报表中字符串日期排序
- file.listFiles()按文件大小、名称、日期排序方法
- c++中sort函数排序自己写的类
- 自定义类型struct的排序-sort函数
- 排序之 快速排序