L2-021 点赞狂魔 (25分)

本文介绍了一个基于C++的程序设计案例,该案例通过使用结构体和标准模板库(STL)中的set来实现对标签出现次数的计算,并根据标签出现次数的平均值进行排序。通过对输入的标签集合进行去重并统计每个实例中不同标签的数量,最终输出标签数量最多且平均值最小的前三个实例名称。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

传送门

track:
标签出现次数平均值最小

#include <bits/stdc++.h>
using namespace std;
int n;

set<int> s;
struct node {
	string name;
	int cnt,avg;
	bool operator <(const node &a){
		if(cnt != a.cnt)
		return cnt > a.cnt;
		return avg < a.avg;
	}
} e[110];


int main() {
	ios::sync_with_stdio(0);
	cin >> n;
	for(int i = 0; i < n; i++) {
		cin >> e[i].name;

		int k,x;
		cin >> k;
		s.clear();
		e[i].avg = k;
		while(k--) {
			cin >> x;
			s.insert(x);
		}
		e[i].cnt = s.size();
	
	}
	sort(e,e+n);

	if(n == 1) cout << e[0].name << " - -" << endl;
	else {
		if(n == 2)	{
			
			cout << e[0].name << " " << e[1].name << " " << "-" << endl;
		} else {
		
			cout << e[0].name << " " << e[1].name << " " << e[2].name << endl;
		}
	}

	return 0;
}
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值