View Code of Problem 3861

#include <iostream>
#include <cstdio>
#include <algorithm>
using namespace std;
struct Pho{
    string name;
    double p,q;
}pho[999];
bool cmp(Pho a,Pho b){
    return a.p/a.q>b.p/b.q;
}
int main(){
    int t;
    cin>>t;
    while(t--){
        int n;
        cin>>n;
        for(int i=0;i<n;i++){
            cin>>pho[i].name>>pho[i].p>>pho[i].q;
        }
        sort(pho,pho+n,cmp);
        for(int i=0;i<n;i++)
            cout<<i+1<<" "<<pho[i].name<<" "<<pho[i].p<<" "<<pho[i].q<<endl;
    }
    return 0;
}

Double click to view unformatted code.


Back to problem 3861