View Code of Problem 3861

#include "stdio.h"
#include "string.h"

void main()
{
	char name[100][21];
	char s[100];
	double temp;
	double a[100][2];
	int t,i,j,x,n;
	double p,q;
	scanf("%d",&t);
	for(x=0;x<t;x++)
	{
		scanf("%d",&n);
		for(i=0;i<n;i++)
		{
		//fflush(stdin);
			scanf("%s",name[i]);
			for(j=0;j<2;j++)
			{
				scanf("%lf",&a[i][j]);
			}
		}
		for(j=0;j<n;j++)
		{
			for(i=0;i<n-j-1;i++)
			{
				p=a[i][0]*1.00/a[i][1];
				q=a[i+1][0]*1.00/a[i+1][1];
				if(p<q)
				{
					strcpy(s,name[i]);strcpy(name[i],name[i+1]);strcpy(name[i+1],s);
					temp=a[i][0];a[i][0]=a[i+1][0];a[i+1][0]=temp;
					temp=a[i][1];a[i][1]=a[i+1][1];a[i+1][1]=temp;
				}
			}
		}
		for(i=0;i<n;i++)
		{
			printf("%d ",i+1);
			printf("%s ",name[i]);
			printf("%.0lf %.0lf\n",a[i][0],a[i][1]);
		}
	}

}

Double click to view unformatted code.


Back to problem 3861