算法提高 身份证排序

问题描述
  安全局搜索到了一批(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;
}



评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值