yipo
5/30/2017 - 9:29 AM

487-3279

487-3279

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

vector<char> create_mapping()
{
    vector<char> mapping(128, '\0');
    for (const string &group : { "0", "1", "2ABC", "3DEF", "4GHI", "5JKL", "6MNO", "7PRS", "8TUV", "9WXY" })
    {
        for (const auto &ch : group) mapping[ch] = group[0];
    }
    return mapping;
}

void normalize(vector<string> &dataset)
{
    transform(dataset.begin(), dataset.end(), dataset.begin(), [](const string &phone_num)
    {
        static const auto &mapping = create_mapping();

        string str;
        for (const auto &ch : phone_num)
        {
            if (ch == '-') continue;
            str.push_back(mapping[ch]);
        }
        return str;
    });
}

map<string, int> find_duplicates(const vector<string> &dataset)
{
    map<string, int> frequency;
    for (const auto &phone_num : dataset) frequency[phone_num]++;

    map<string, int> duplicates;
    for (const auto &pair : frequency)
    {
        if (pair.second > 1) duplicates.insert(pair);
    }
    return duplicates;
}

void test_case()
{
    int n;
    cin >> n;
    vector<string> dataset(n);
    for (auto &phone_num : dataset) cin >> phone_num;

    normalize(dataset);
    map<string, int> duplicates = find_duplicates(dataset);

    if (duplicates.empty())
    {
        cout << "No duplicates." << endl;
    }
    else
    {
        for (const auto &pair : duplicates)
        {
            cout << pair.first.substr(0, 3) << "-" << pair.first.substr(3) << " " << pair.second << endl;
        }
    }
}

int main()
{
    int n;
    cin >> n;
    while (n--)
    {
        test_case();
        if (n > 0) cout << endl;
    }
    return 0;
}