#include<iostream> #include<vector> #include<algorithm> #include<iomanip> #include<string> #include<cmath> #include<unordered_map> #include<stack> using namespace std; struct phone { string name; double grade; double money; }; bool cmp(phone a, phone b) { double aa = (double)(a.grade / a.money); double bb = (double)(b.grade / b.money); return aa > bb; } int main() { int T; cin >> T; for (int i = 0; i < T; i++) { int n; cin >> n; vector<phone> phones(n); for (int j = 0; j < n; j++) { cin >> phones[j].name >> phones[j].grade >> phones[j].money; } sort(phones.begin(), phones.end(), cmp); for (int j = 0; j < n; j++) { cout << j + 1 << " " << phones[j].name << " " << phones[j].grade << " " << phones[j].money << endl; } } } |
Double click to view unformatted code.