View Code of Problem 3861

#include <stdio.h>
#include <string.h>
#include <math.h>
#include<algorithm>
#include<string>
#include<iostream>
using namespace std;
struct phone {
	string name;
	double p;
	double q;
};
bool cmp(phone x, phone y) {
	return (x.p / x.q) > (y.p / y.q);
}
int main() {
	int t,n;
	phone arr[101];
	scanf("%d", &t);
	while (t--) {
		scanf("%d", &n);
		for (int i = 0; i < n; i++) {
			cin >> arr[i].name >> arr[i].p >> arr[i].q;
		}
		sort(arr, arr + n, cmp);
		for (int i = 0; i < n; i++) {
			cout << i + 1 <<" "<< arr[i].name <<" " <<arr[i].p << " "<<arr[i].q<<endl;
		}
	}
	return 0;
}
/*
Main.c:4:9: fatal error: algorithm: No such file or directory
 #include<algorithm>
         ^~~~~~~~~~~
compilation terminated.
*/

Double click to view unformatted code.


Back to problem 3861