为什么不注释掉倒数第3行的sort就(系统)报错

9. 家族迁徙

#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 sort(fish a,fish b){
	if(a.y!=b.y) return a.year<b.year;
	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) 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) 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].stastus;
	}
//	sort(a,a+n);
	for(int i=0;i<n;i++) cout<<a[i].name<<endl; 
	return 0;
}

bool sort?
用比较函数排序

2 个赞

谢谢

1 个赞