9.家族迁徙 WA 25分

#include<bits/stdc++.h>
using namespace std;
int n;
struct fish{
	int year,hao,y,sex;
	string region,name,number,stastus,can,day;
}a[1010]; 
bool cmp(fish a,fish b){
	if(a.y!=b.y) return a.y<b.y;
	if(a.y==1){
		if(a.year!=b.year) return a.year<b.year;
		return a.hao<b.hao;
	}else if(a.y==2){
		if(a.year!=b.year) return a.year>b.year;
		return a.hao<b.hao;	
	}else{
		if(a.sex%2!=b.sex%2) return a.sex%2<b.sex%2;
		if(a.sex%2==0&&a.year!=b.year) return a.year<b.year;
		if(a.sex%2==0) return a.hao<b.hao;
		if(a.hao%2==1&&a.can!=b.can){
			if(a.can.size()!=b.can.size()) return a.can.size()<b.can.size();
			return a.can<b.can;
		} 
		return a.hao<b.hao;
	}
} 
int main(){
	cin>>n;
	for(int i=0;i<n;i++){
		a[i].hao=i;
		cin>>a[i].name;
		for(int j=0;j<6;j++) cin>>a[i].region[j];
		string s;
		for(int j=0;j<4;j++){
			cin>>s[j]; 
			a[i].year=a[i].year*10+(s[j]-'0');
		} 
		a[i].year=2000-a[i].year;
		if(a[i].year<100) a[i].y=1;
		else if(a[i].year>1000) a[i].y=2;
		else a[i].y=3; 
		for(int j=0;j<4;j++) cin>>a[i].day[j];
		for(int j=0;j<2;j++) cin>>a[i].number[j];
		char x;
		cin>>x;
		a[i].sex=x-'0';
		for(int j=0;j<1;j++) cin>>a[i].stastus[j];
		cin>>a[i].can;
	}
	sort(a,a+n,cmp);
	for(int i=0;i<n;i++) cout<<a[i].name<<endl; 
	return 0;
}

stable_sort()用这个,保持排序的稳定性

老师,不是这个问题

长度不固定,这样可能遗漏数据