转换后的快排
#include<stdio.h>
#include<stdlib.h>
#define MAXN 100000
int a[MAXN][3];
int compare(const void * x, const void * y)
{
if(*(int*)x > *(int*)y)return 1;
else if(*(int*)x == *(int*)y) if(*((int*)x + 2) > *((int*)y + 2)) return 1;
return -1;
}
int main()
{
int n, i, j;
freopen("in.txt", "r", stdin);
freopen("out.txt", "w", stdout);
while(scanf("%d",&n) == 1)
{
for(i = 0; i < n; i++) scanf("%d%d",&a[i][0],&a[i][1]);
for(i = 0; i < n; i++) a[i][2] = i;
qsort(a,n,3*sizeof(int),compare);
for(i = 0; i < n; i++) printf("%d %d\n",a[i][0],a[i][1]);
}
return 0;
}