#include<bits/stdc++.h> using namespace std; typedef struct{ string name; int paofen; int price; double kk; }phone; bool cmp(phone a,phone b){ return a.kk>b.kk; } int main(){ phone p[1000]; int T; cin>>T; while(T--){ int n; cin>>n;getchar();//n 个手机 for(int i=0;i<n;i++){ cin>>p[i].name>>p[i].paofen>>p[i].price; p[i].kk=p[i].paofen*1.0/p[i].price; } sort(p,p+n,cmp); for(int i=0;i<n;i++){ cout<<i+1<<" "<<p[i].name<<" "<<p[i].paofen<<" "<<p[i].price<<endl; } } } |
Double click to view unformatted code.