ural1100 Final Standings

#include <cstdlib>

#include <iostream>

#include <cstdio> 



using namespace std;



#define X 150001



typedef struct node

{

	int id,m;

	int key; //按顺序

}node;



struct node f[X];



int cmp(const void *a,const void *b)

{

	struct node *c=(node *)a; //强转

	struct node *d=(node *)b;

	if(d->m==c->m) //如果相等,按顺序排列

	return c->key-d->key;

	return d->m-c->m;

}



int main()

{

	freopen("sum.in","r",stdin);

	freopen("sum.out","w",stdout);

	int n,i;

	while(cin>>n)

	{

		for(i=0;i<n;i++)

		{

			cin>>f[i].id>>f[i].m;

			f[i].key=i; //标记顺序

		}

		qsort(f,n,sizeof(f[0]),cmp); //快排

		for(i=0;i<n;i++)

		printf("%d %d\n",f[i].id,f[i].m);

	}

	return 0;

}

  

你可能感兴趣的:(final)