View Code of Problem 3861

#include<bits/stdc++.h>
using namespace std;
#define max 101
struct phone{
	string name;
	int price;
	int k;
	double now;
};
bool cmp(phone a,phone b);
int main(){
	phone P[max];
	int n,m;  
	cin>>n;
	for(int u = 0;u < n;u++){
		
		cin>>m;
		for( int i = 0;i < m;i++ ){
			cin>>P[i].name>>P[i].k>>P[i].price;
			P[i].now = P[i].price * 1.0 / P[i].k;
		}
		sort(P,P+m,cmp);
		int op = 1;
		for(int i = 0;i < m;i++){
			cout<<op<<" "<<P[i].name<<" "<<P[i].k<<" "<<P[i].price<<endl;
			op++;
		}
		
		
		
		
		
		
	}
	
	
	
	
	
	
	
	
	
	
	
	return 0;
}
bool cmp(phone a,phone b){
	return a.now < b.now;
}

Double click to view unformatted code.


Back to problem 3861