L2-2 点赞狂魔

微博上有个“点赞”功能,你可以为你喜欢的博文点个赞表示支持。每篇博文都有一些刻画其特性的标签,而你点赞的博文的类型,也间接刻画了你的特性。然而有这么一种人,他们会通过给自己看到的一切内容点赞来狂刷存在感,这种人就被称为“点赞狂魔”。他们点赞的标签非常分散,无法体现出明显的特性。本题就要求你写个程序,通过统计每个人点赞的不同标签的数量,找出前3名点赞狂魔。

输入格式:

输入在第一行给出一个正整数N(≤100),是待统计的用户数。随后N行,每行列出一位用户的点赞标签。格式为“Name K F1​⋯FK​”,其中Name是不超过8个英文小写字母的非空用户名,1≤K≤1000,Fi​(i=1,⋯,K)是特性标签的编号,我们将所有特性标签从 1 到 107 编号。数字间以空格分隔。

输出格式:

统计每个人点赞的不同标签的数量,找出数量最大的前3名,在一行中顺序输出他们的用户名,其间以1个空格分隔,且行末不得有多余空格。如果有并列,则输出标签出现次数平均值最小的那个,题目保证这样的用户没有并列。若不足3人,则用-补齐缺失,例如mike jenny -就表示只有2人。

输入样例:

5
bob 11 101 102 103 104 105 106 107 108 108 107 107
peter 8 1 2 3 4 3 2 5 1
chris 12 1 2 3 4 5 6 7 8 9 1 2 3
john 10 8 7 6 5 4 3 2 1 7 5
jack 9 6 7 8 9 10 11 12 13 14

#include <iostream>
using namespace std;
#include <vector>
#include <unordered_map>
#include <string>
#include <algorithm>

struct {
    string str = "";
    int count1 = 0;
    int count2 = 0;
}s[100];

int main() {
    int n, x; cin >> n;
    unordered_map<string, vector<int>>mp;
    for (int i = 0; i < n; i++) {
        string str; cin >> str;
        int k; cin >> k;
        s[i].str = str;
        while (cin >> x) {
            mp[str].push_back(x);
            if (cin.peek() == '\n') break;
        }
        s[i].count1 = k;
        sort(mp[str].begin(), mp[str].end());
        mp[str].erase(unique(mp[str].begin(), mp[str].end()), mp[str].end());
        s[i].count2 = mp[str].size();
    }
    sort(s, s + n, [](const auto& a, const auto& b) {
        return ((a.count2 > b.count2) || ((a.count2 == b.count2) && a.count1 < b.count1));
        });
    for (int i = 0; i < 3; i++) {
        if (i < n) {
            cout << s[i].str;
        }
        else {
            cout << "-";
        }
        if (i == 2) cout << endl;
        else cout << ' ';
    }
    return 0;
}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值