View Code of Problem 3861

#include <iostream>
#include<stdio.h>
#include <string.h>
#include<cstring>
#include <math.h>
#include<algorithm>
#include <stack>
using namespace std;

typedef struct {
	string name;
	double p;
	double price;
}Item;

bool cmp(Item a, Item b) {
	double ac = a.p / a.price;
	double bc = b.p / b.price;
	return ac > bc;
}

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

Double click to view unformatted code.


Back to problem 3861