PAT(A) 1025

快排有问题,出现段错误,后来改用qsort过了
#include
#include
#include
typedef struct pat Element;
struct pat{
	char id[15];
	int score;
	int local;
	int localrank;
	int totalrank;
} stu[30005];
int compare(struct pat a,struct pat b){
	if(a.score == b.score)
		return strcmp(a.id,b.id);
	else return b.score - a.score;
}
void swamp(Element *a,Element *b){
	Element tmp;
	tmp = *a;
	*a = *b;
	*b = tmp;
}
Element median3(Element a[],int begin,int end){
	int mid;
	mid = (begin + end)/2;
	if(compare(a[begin],a[mid])>0)
		swamp(&a[begin],&a[mid]);
	if(compare(a[begin],a[end])>0)
		swamp(&a[begin],&a[end]);
	if(compare(a[mid],a[end])>0)
		swamp(&a[mid],&a[end]);
	swamp(&a[mid],&a[end-1]);
	return a[end-1];
}
void Insertsort(Element a[],int n){
	int i,j;
	Element tmp;
	for(i = 1;i0;j--)
			a[j] = a[j-1];
		a[j] = tmp;
	}
}
void partition(Element a[],int begin,int end){
	int i,j;
	Element pivot;
	if(end - begin>4){
		pivot = median3(a,begin,end);
		i = 0;
		j = end-1;
		while(1){
			while(compare(a[++i],pivot)<0);
			while(compare(a[--j],pivot)>0);
			if(i

你可能感兴趣的:(Pat)