View Code of Problem 3861

#include <iostream>
#include <algorithm>
using namespace std;
struct phone{
	char name[22];
	float sorce;
	float  price;
	double x;
};
bool cmp(phone a,phone b){
	return a.x<b.x;
}
int main(int argc, char *argv[])
{
	int t,n;
	scanf("%d",&t);
	while(t--){
		scanf("%d",&n);
		phone p[n];
		for(int i = 0;i<n;i++){
			scanf("%s %f %f",p[i].name,&p[i].sorce,&p[i].price);
			 p[i].x= p[i].sorce/p[i].price; 
		}
		sort(p,p+n,cmp);
		int j = 1;
		for(int i = n-1;i>=0;i--){
			printf("%d %s %.0f %.0f\n",j++, p[i].name,p[i].sorce,p[i].price);
		}
	}
	return 0;
}

Double click to view unformatted code.


Back to problem 3861