View Code of Problem 3861

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

Double click to view unformatted code.


Back to problem 3861