View Code of Problem 3861

#include<stdio.h>
#include<string.h>
struct phone
{
	char name[20];
	double p;
	double q;
};
int main()
{
	int n,i,j,t,k;
	scanf("%d",&t);
	for(k=0;k<t;k++)
	{
	scanf("%d",&n);
	struct phone ph[100],temp;
	int a[100];
	for(i=0;i<n;i++)
	{
		scanf("%s%lf%lf",ph[i].name,&ph[i].p,&ph[i].q);
		a[i]=ph[i].p/ph[i].q;
	}
	char b[100];
	int p1,q1,h;
	for(i=0;i<n-1;i++)
	{
		for(j=0;j<n-i-1;j++)
		{
			if(a[j]<a[j+1])
			{
				h=a[j];
				a[j]=a[j+1];
				a[j+1]=h;
                temp=ph[j];
                ph[j]=ph[j+1];
                ph[j+1]=temp;
				
			}
		}
	}
	for(i=0;i<n;i++)
		printf("%d %s %.0lf %.0lf\n",i+1,ph[i].name,ph[i].p,ph[i].q);
   } 	
	return 0;
}

Double click to view unformatted code.


Back to problem 3861