View Code of Problem 3861

#include<stdio.h>
#include<math.h>
#include<string.h>
//#include<algorithm>
#include <bits/stdc++.h>

using namespace std;

typedef struct ph {
	char str[100];
	int p;
	int q;
	double rate;
} ph;

bool cmp(ph a,ph b) {
	if(a.rate>b.rate) {
		return true;
	} else {
		return false;
	}
}

int main() {
	int T;
	scanf("%d",&T);
	while(T--) {
		int n;
		ph p[101];
		scanf("%d",&n);
		for(int i=0; i<n; i++) {
			scanf("%s %d %d",p[i].str,&p[i].p,&p[i].q);
			p[i].rate=(double)p[i].p/(double)p[i].q;
		}
		sort(p,p+n,cmp);
		for(int i=0; i<n; i++) {
			printf("%d %s %d %d\n",i+1,p[i].str,p[i].p,p[i].q);
		}

	}
}

Double click to view unformatted code.


Back to problem 3861