天梯赛 L2 点赞狂魔

题目链接:点击打开链接

思路:STL set + 排序

#include 
using namespace std;
string name[105];
int num[105];
double aver[105];
int cnt[105];
set s;
struct node{
	int index,count;
	double average;
	node(int a,int b,double c):index(a),count(b),average(c){}
	bool operator<(const node &b)const{
		if(count != b.count){
			return count > b.count;
		}
		else{
			return average < b.average;
		}
	} 
};
int main(){
	int te,n;
	cin >> n;
	for(int i = 0;i < n;i++){
		s.clear();
		cin >> name[i] >> num[i];
		for(int j = 0;j < num[i];j++){
			cin >> te;
			s.insert(te);
		}
		cnt[i] = s.size();
		aver[i] = (double)num[i] / cnt[i];
	}
	vector v;
	for(int i = 0;i < n;i++){
		v.push_back(node(i,cnt[i],aver[i]));
	}
	sort(v.begin(),v.end());
	if(n == 1){
		cout << name[v[0].index] << " -" << " -"<

你可能感兴趣的:(天梯赛)