#include<iostream> #include<algorithm> using namespace std; struct Phone { string name; int goal,price; double rare; }a[110]; bool cmp(Phone a,Phone b) { return a.rare > b.rare; } int main() { int t; cin >> t; while(t --) { int n; cin >> n; for(int i = 0;i < n;i ++) { cin >> a[i].name >> a[i].goal >> a[i].price; a[i].rare = a[i].goal / a[i].price; } sort(a,a+n,cmp); int k = 1; for(int i = 0;i < n;i ++) { if(i == 0) { cout << k ++ << " " << a[i].name << " " << a[i].goal << " " << a[i].price; } else { cout << endl << k ++ << " " << a[i].name << " " << a[i].goal << " " << a[i].price; } } cout << endl; } return 0; } |
Double click to view unformatted code.