View Code of Problem 3861

#include <iostream>
#include <algorithm>
#include <string>

using namespace std;
struct phone{
	string name;
	double xing;
	double jia;
	double bi;
};
bool cmp(phone a,phone b){
	return a.bi>b.bi;
}
int main(){
	int t;
	cin>>t;
	for(int i=0;i<t;i++){
		int n;
		cin>>n;
		phone plist[n];
		for(int j=0;j<n;j++){
			cin>>plist[j].name>>plist[j].xing>>plist[j].jia;
			plist[j].bi=plist[j].xing/plist[j].jia;
		}
		sort(plist,plist+n,cmp);
		for(int j=0;j<n;j++){
			cout<<j+1<<" "<<plist[j].name<<" "<<plist[j].xing<<" "<<plist[j].jia<<endl;
		}
	}
	return 0;
}

Double click to view unformatted code.


Back to problem 3861