问题描述
安全局搜索到了一批(n个)身份证号码,希望按出生日期对它们进行从大到小排序,如果有相同日期,则按身份证号码大小进行排序。身份证号码为18位的数字组成,出生日期为第7到第14位
输入格式
第一行一个整数n,表示有n个身份证号码
余下的n行,每行一个身份证号码。
余下的n行,每行一个身份证号码。
输出格式
按出生日期从大到小排序后的身份证号,每行一条
样例输入
5
466272307503271156
215856472207097978
234804580401078365
404475727700034980
710351408803093165
466272307503271156
215856472207097978
234804580401078365
404475727700034980
710351408803093165
样例输出
404475727700034980
234804580401078365
215856472207097978
710351408803093165
466272307503271156
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;
}