PAT 天梯赛 L2-021. 点赞狂魔 【水】

题目链接

https://www.patest.cn/contests/gplt/L2-021

题意
给出一个若干个人名,后面给出点赞的总数,以及每个赞的标签类型,输出前三个点赞狂魔,按标签类型不同数递减排序,如果相同,则按总数递增排序

思路
用MAP 标记,统计最后有几个不同的标签类型,然后用结构体存

AC代码

#include 
#include 
#include 
#include 
#include 
#include 
#include 
#include 
#include 
#include 
#include 
#include 
#include 
#include 
#include 
#include 
using namespace std;

typedef long long LL;
const double PI  = 3.14159265358979323846264338327;
const double E   = 2.718281828459;  
const double eps = 1e-6;
const int MAXN   = 0x3f3f3f3f;
const int MINN   = 0xc0c0c0c0;
const int maxn   = 1e2 + 5; 
const int MOD    = 1e9 + 7;
struct node
{
    string s;
    int tot;
    int k;
}temp;
int comp (node x, node y)
{
    if (x.tot == y.tot)
        return x.k < y.k;
    return x.tot > y.tot;
}
vector  q;
int main()
{
    int n;
    int i, j;
    map <int, int> vis;
    string s;
    int k, tot, num;
    cin >> n;
    for (i = 0; i < n; i++)
    {
        vis.clear();
        cin >> temp.s >> temp.k;
        temp.tot = 0;
        for (j = 0; j < temp.k; j++)
        {
            scanf("%d", &num);
            if (vis[num] == 0)
                temp.tot++;
            vis[num]++;
        }
        q.push_back(temp);
    }
    sort (q.begin(), q.end(), comp);
    temp.s = "-";
    for (i = 0; i < 3; i++)
        q.push_back(temp);
    for (i = 0; i < 3; i++)
    {
        if (i)
            printf(" ");
        cout << q[i].s;
    }
    cout << endl;
}

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