View Code of Problem 3861

#include "stdlib.h"
#include "algorithm"
#include "iostream"
#include <cstdio>
#include "string"
#include <iomanip>
#include <map>
#include <set>
#include "math.h"
using namespace std;
map<int, bool> mp;
set<string> st;
typedef struct a
{
	string name;
	double p;
	double q;
	double num;
}Ph;
int cmp(Ph x,Ph y)
{
	return y.num < x.num;
}
int main() 
{
	int t, n; cin >> t; Ph x[1000];
	while (t--)
	{
		cin >> n;
		for (int i = 0; i < n; i++)
		{
			cin >> x[i].name >> x[i].p >> x[i].q;
			x[i].num = x[i].p / x[i].q;
		}
		sort(x,x+n,cmp);
		for (int i = 0; i < n; i++)
		{
			cout << i + 1 << " " << x[i].name << " " << x[i].p << " " << x[i].q << endl;
		}
	}
	return 0;
}

Double click to view unformatted code.


Back to problem 3861