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