PTA L2-021 点赞狂魔

// ConsoleApplication62.cpp : This file contains the 'main' function. Program execution begins and ends there.
//
#pragma warning(disable:4996)
#include <iostream>
#include <algorithm>
#include <set>
#include <vector>

class K
{
public:
    K() {}
    K(std::string ss, int aa, double bb) :s(ss), a(aa), b(bb) {}
    std::string s;
    int a;
    double b;
};

bool cmp(K k1, K k2)
{
    if (k1.a == k2.a)
        return k1.b > k2.b;
    return k1.a > k2.a;
}

int n;
std::vector<K> vk;

int main()
{
    std::cin >> n;
    for (int i = 0; i < n; i++)
    {
        std::string name;
        int j;
        std::cin >> name >> j;
        std::set<int> s;
        for (int k = 0; k < j; k++)
        {
            int l;
            std::cin >> l;
            s.insert(l);
        }
        int sz = s.size();
        vk.push_back({ name, sz, (double) sz / j });
    }

    std::sort(vk.begin(), vk.end(), cmp);

    for (int i = 0; i < 3; i++)
    {
        if (i < vk.size())
            std::cout << vk[i].s;
        else
            std::cout << "-";
        if (i != 3 - 1)
            printf(" ");
    }
}

 

上一篇:redis03-list/set/sorted_set/hash


下一篇:Windows 10 下编译 libmp3lame3.100