View Code of Problem 3861

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

Double click to view unformatted code.


Back to problem 3861