View Code of Problem 3861

#include<iostream>
#include<algorithm>
using namespace std;
const int N = 100010;
struct phone
{
	string name;
	double xingneng,price;
}a[N];
bool cmp(phone x,phone y)
{
	return x.xingneng / x.price > y.xingneng / y.price;
}
int main()
{
	int t;
	cin >> t;
	while(t --)
	{
		int n;
		int k = 1;
		cin >> n;
		for(int i = 0;i < n;i ++)
		{
			cin >> a[i].name >> a[i].xingneng >> a[i].price;
		}
		sort(a,a + n,cmp);
		for(int i = 0;i < n;i ++) 
			cout << k ++ << " " << a[i].name << " " << a[i].xingneng << " " << a[i].price << endl;
	}
	return 0;
}

Double click to view unformatted code.


Back to problem 3861