View Code of Problem 3861

#include <iostream>
#include <algorithm>
using namespace std;
typedef struct phone{
	string name;
	int xingneng;
	int price;
}phone;
bool cmp(phone x,phone y){
	double x1 = x.xingneng/x.price;
	double y1 = y.xingneng/y.price;
	return x1>y1;
}
int main(){
	int t,n;
	cin>>t;
	while(t--){
		cin>>n;
		phone p[n];
		for(int i=0;i<n;i++){
			cin>>p[i].name;
			cin>>p[i].xingneng;
			cin>>p[i].price;
		}
		sort(p+0,p+n,cmp);
		for(int i=0;i<n;i++){
			cout<<i+1<<" "<<p[i].name<<" "<<p[i].xingneng<<" "<<p[i].price;
			if(i!=n-1) cout<<endl; 
		}
	}
	
}

Double click to view unformatted code.


Back to problem 3861