View Code of Problem 3861

#include <iostream>
#include <algorithm>
using namespace std;

typedef struct{
	string name;
	int p;
	int q;
	double x;
}Phone;

bool cmp(Phone a,Phone b){
	return a.x>b.x;
}

int main(){
	int t;
	cin>>t;
	while(t--){
		int n;
		cin>>n;
		Phone p[n];
		for(int i=0;i<n;i++){
			cin>>p[i].name>>p[i].p>>p[i].q;
			p[i].x=(double)p[i].p/p[i].q;
		}
		sort(p,p+n,cmp);
		for(int i=0;i<n;i++){
			cout<<i+1<<" "<<p[i].name<<" "<<p[i].p<<" "<<p[i].q<<endl; 
		}
	}
}

Double click to view unformatted code.


Back to problem 3861