View Code of Problem 3861

#include<stdio.h>
#include<string.h>
#include<ctype.h> 
#include<algorithm>
using namespace std;
struct phone{
	char name[30];
	int p;
	int q;
}pe[110];
bool cmp(phone a,phone b)
{
	return a.p/a.q>b.p/b.q;
}
int main()
{
	int i,t,n;
	scanf("%d",&t);
	while(t--)
	{
		scanf("%d",&n);
	//	getchar();
		for(i=0;i<n;i++)
		{
			scanf("%s%d%d",&pe[i].name,&pe[i].p,&pe[i].q);
		}
		sort(pe,pe+n,cmp);
		for(i=0;i<n;i++)
		{
			printf("%d %s %d %d\n",i+1,pe[i].name,pe[i].p,pe[i].q);
		}
	}
	return 0;
 } 

Double click to view unformatted code.


Back to problem 3861