View Code of Problem 3861

#include<iostream>
#include<string>
#include<algorithm> 
using namespace std;
typedef struct 
{
	string name;
	double p,q,ans; 
} phone;
bool mycmp(phone s1,phone s2)
{
	return s1.ans > s2.ans;
}
int main()
{
	int i,t,n;
	 cin>>t;
		while(t--)
		{
			cin>>n;
			phone ph[n];
			for( i=0;i<n;i++ )
			{
				cin>>ph[i].name>>ph[i].p>>
				ph[i].q;
				ph[i].ans=ph[i].p/ph[i].q;
			}
			sort(ph,ph+n,mycmp);
			for( i=0;i<n;i++ )
			cout<<i+1<<" "<<ph[i].name<<" "<<
			ph[i].p<<" "<<ph[i].q<<endl;
		} 
	return 0;
}

Double click to view unformatted code.


Back to problem 3861