View Code of Problem 3861

#include <bits/stdc++.h>
using namespace std;
struct phone {
	string name;
	int perf;
	int price;
}p[100];
int cmp(phone p1, phone p2) {
	int d1 = p1.perf * p1.price;
	int d2 = p2.perf * p2.price;
	return d1 < d2 ? 1 : 0;
}
int main() {
	int t;
	cin >> t;
	while (t--) {
		int n;
		cin >> n;
		for (int i=0;i<n;++i) {
			cin >> p[i].name >> p[i].perf >> p[i].price;
		}
		sort(p, p + n, cmp);
		for (int i = 0; i < n; ++i) {
			cout << i+1 << ' ' << p[i].name << ' ' << p[i].perf << ' ' << p[i].price << endl;
		}
		
		
	}
}

Double click to view unformatted code.


Back to problem 3861