View Code of Problem 3861

#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
struct phone{
	char name[25];
	int p, q;
	int s;
}ph[105];
bool cmp(phone a, phone b){
	return a.s>b.s;
}
int main (){
	int t, n;
	scanf("%d", &t);
	while(t--){
		scanf("%d", &n);
		for(int i = 0;i < n;i++){
			scanf("%s%d%d", ph[i].name, &ph[i].p, &ph[i].q);
			ph[i].s = ph[i].p/ph[i].q;
		}
		sort(ph, ph+n, cmp);
		for(int i = 0;i < n;i++){
			printf("%d %s %d %d\n", i+1, ph[i].name, ph[i].p, ph[i].q);
		}
	}

	return 0;
}

Double click to view unformatted code.


Back to problem 3861