View Code of Problem 3861

#include<bits/stdc++.h>
using namespace std;
typedef struct phone{
	string name;
	int p;
	int q;
	phone(){};
	phone(string name,int p,int q):name(name),p(p),q(q){};
}phone;
bool cmp(phone a,phone b){
	return (1.0*a.p/a.q)>(1.0*b.p/b.q);
}
int main(){
	int t;
	cin>>t;
	while(t--){
		int n;
		cin>>n;
		vector<phone> v;
		for(int i=0;i<n;i++){
			string name;
			int p,q;
			cin>>name>>p>>q;
			phone temp(name,p,q);
			v.push_back(temp);
		}
		sort(v.begin(),v.end(),cmp);
		for(int i=0;i<v.size();i++){
			cout<<i+1<<" "<<v[i].name<<" "<<v[i].p<<" "<<v[i].q<<endl;
		}	
	}	
} 

Double click to view unformatted code.


Back to problem 3861