View Code of Problem 3861

#include<stdio.h>
#include<math.h>
struct student{
	char name[100];
	double p;
	double q;
}s[100];
int main(){
	int n,t,i,j;
	struct student s[100],d;

	scanf("%d",&t);
	while(t--)
	{
		double x[100]={0};
		scanf("%d",&n);
		for(i=0;i<n;i++)
			scanf("%s%lf%lf",&s[i].name,&s[i].p,&s[i].q);

		for(i=0;i<n;i++)
			for(j=i;j<n;j++)
				if(s[i].p/s[i].q<s[j].p/s[j].q)
				{
					d=s[i];
					s[i]=s[j];
					s[j]=d;
				}
		for(i=0;i<n;i++)
			printf("%d %s %0.0f %0.0f\n",i+1,s[i].name,s[i].p,s[i].q);				
	}

	return 0;
}

Double click to view unformatted code.


Back to problem 3861