View Code of Problem 3861

#include<iostream>
#include<algorithm>
#include<vector>
#include<string>
using namespace std;
struct ph {
	string na;
	int a;
	int b;
};
bool cmp(ph x,ph y) {
	return x.a *y.b > y.a*x.b;
}
int main(){
	int T; cin >> T;
	while (T--) {
		int n; cin >> n;
		vector<ph> p(n);
		for (int i = 0; i < n; i++)
			cin >>p[i].na>> p[i].a >> p[i].b;
		sort(p.begin(), p.end(), cmp);
		for (int i = 0; i < n; i++)
			cout <<i+1<<' '<< p[i].na << ' ' << p[i].a << ' ' << p[i].b << endl;
	}
}

Double click to view unformatted code.


Back to problem 3861