View Code of Problem 3861

#include<stdio.h>
#include<string.h>
#include<ctype.h> 
#include<algorithm>
using namespace std;
struct phone{
	char name[30];
	float p;
	float 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);
		for(i=0;i<n;i++)
		{
			scanf("%s%f%f",pe[i].name,&pe[i].p,&pe[i].q);
		}
		sort(pe,pe+n,cmp);
		for(i=0;i<n;i++)
		{
			printf("%d %s %.0f %.0f\n",i+1,pe[i].name,pe[i].p,pe[i].q);
		}
	}
	return 0;
 } 

Double click to view unformatted code.


Back to problem 3861