yipo
3/26/2018 - 4:59 PM

uva12015

Google is Feeling Lucky

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

template <typename T, typename Compare>
vector<T> max_elements(const vector<T> &list, Compare comp)
{
    if (list.empty()) return {};

    vector<T> maxes = { list.front() };

    for (size_t i = 1; i < list.size(); i++)
    {
        const auto &value = list.at(i);
        const auto &max = maxes.front();

        if (comp(value, max))
        {
            maxes = { value };
        }
        else if (!comp(max, value))
        {
            maxes.push_back(value);
        }
    }
    return maxes;
}

void test_case(size_t case_num)
{
    using element = pair<string, int>;
    vector<element> list;

    for (size_t i = 0; i < 10; i++)
    {
        string url;
        int score;
        cin >> url >> score;

        list.push_back(make_pair(url, score));
    }

    auto result = max_elements(list, [](const element &a, const element &b)
    {
        return a.second > b.second;
    });

    cout << "Case #" << case_num << ":" << endl;
    for (const auto &p : result)
    {
        cout << p.first << endl;
    }
}

int main()
{
    size_t n;
    cin >> n;

    for (size_t i = 1; i <= n; i++) test_case(i);
    return 0;
}