算法提高 身份证排序
2017-05-24 20:14
211 查看
问题描述
安全局搜索到了一批(n个)身份证号码,希望按出生日期对它们进行从大到小排序,如果有相同日期,则按身份证号码大小进行排序。身份证号码为18位的数字组成,出生日期为第7到第14位
输入格式
第一行一个整数n,表示有n个身份证号码
余下的n行,每行一个身份证号码。
输出格式
按出生日期从大到小排序后的身份证号,每行一条
样例输入
5
466272307503271156
215856472207097978
234804580401078365
404475727700034980
710351408803093165
样例输出
404475727700034980
234804580401078365
215856472207097978
710351408803093165
466272307503271156
数据规模和约定
n<=100000
C++中substr函数的用法
#include<string>
#include<iostream>
using namespace std;
main()
{
string s("12345asdf");
string a=s.substr(0,5); //获得字符串s中 从第0位开始的长度为5的字符串//默认时的长度为从开始位置到尾
cout<<a<<endl;
}
输出结果为:
12345
#include<iostream>
#include<algorithm>
#include<cstdio>
#include<climits>
#include<vector>
#include<cstring>
using namespace std;
typedef struct node{
string s,t;
}NO;
bool comper(NO a, NO b){
if(a.t>b.t)return true;
else if(a.t==b.t&&a.s>b.s)return true;
return false;
}
int main(){
int n;
NO no[100000];
cin>>n;
for(int i=0;i<n;i++){
cin>>no[i].s;
no[i].t=no[i].s.substr(6,8);
}
sort(no,no+n,comper);
for(int i=0;i<n;i++){
cout<<no[i].s<<endl;
}
return 0;
}
安全局搜索到了一批(n个)身份证号码,希望按出生日期对它们进行从大到小排序,如果有相同日期,则按身份证号码大小进行排序。身份证号码为18位的数字组成,出生日期为第7到第14位
输入格式
第一行一个整数n,表示有n个身份证号码
余下的n行,每行一个身份证号码。
输出格式
按出生日期从大到小排序后的身份证号,每行一条
样例输入
5
466272307503271156
215856472207097978
234804580401078365
404475727700034980
710351408803093165
样例输出
404475727700034980
234804580401078365
215856472207097978
710351408803093165
466272307503271156
数据规模和约定
n<=100000
C++中substr函数的用法
#include<string>
#include<iostream>
using namespace std;
main()
{
string s("12345asdf");
string a=s.substr(0,5); //获得字符串s中 从第0位开始的长度为5的字符串//默认时的长度为从开始位置到尾
cout<<a<<endl;
}
输出结果为:
12345
#include<iostream>
#include<algorithm>
#include<cstdio>
#include<climits>
#include<vector>
#include<cstring>
using namespace std;
typedef struct node{
string s,t;
}NO;
bool comper(NO a, NO b){
if(a.t>b.t)return true;
else if(a.t==b.t&&a.s>b.s)return true;
return false;
}
int main(){
int n;
NO no[100000];
cin>>n;
for(int i=0;i<n;i++){
cin>>no[i].s;
no[i].t=no[i].s.substr(6,8);
}
sort(no,no+n,comper);
for(int i=0;i<n;i++){
cout<<no[i].s<<endl;
}
return 0;
}
相关文章推荐
- 蓝桥杯 算法提高 身份证排序
- 算法提高 身份证排序
- 蓝桥杯算法提高 身份证排序
- 蓝桥杯ADV-172 算法提高 身份证排序
- 算法提高 身份证号码升级
- 蓝桥杯_算法提高_快乐的司机(快速排序、贪心算法)
- 算法提高 身份证号码升级
- 算法提高 选择排序
- C++提高5 STL算法 :查找,统计,排序,拷贝,替换,算术,集合 |STL 案例:学校演讲比赛介绍
- 算法提高 12-2扑克排序
- 算法提高 身份证号码升级
- 算法提高 快乐司机 (排序,贪心)
- 算法提高 三个整数的排序
- 蓝桥杯 算法提高 选择排序
- 蓝桥杯 - 算法提高 快乐司机 ( 排序+贪心 )
- 蓝桥杯 ADV-171 算法提高 身份证号码升级
- 算法提高 身份证号码升级 JAVA
- 蓝桥杯_算法提高_身份证升级(简单字符处理)
- 算法提高 12-2扑克排序
- 算法笔记_101:蓝桥杯练习 算法提高 身份证号码升级(Java)