7-136 4112 487-3279

#include <algorithm>
#include <cstdint>
#include <iostream>
#include <limits>
#include <numeric>
#include <string>
#include <unordered_map>
#include <utility>
#include <vector>

using i32 = std::int32_t;
using i64 = std::int64_t;
using u32 = std::uint32_t;
using u64 = std::uint64_t;
using pii = std::pair<i32, i32>;
using pll = std::pair<i64, i64>;
using vi = std::vector<i32>;
using vll = std::vector<i64>;
using vpii = std::vector<pii>;
using vpll = std::vector<pll>;

void solve();

int main()
{
    std::cin.tie(nullptr)->sync_with_stdio(false);
    solve();
}

char query(char x)
{
    const std::vector<std::string> map{"ABC", "DEF", "GHI", "JKL", "MNO", "PRS", "TUV", "WXY"};
    for (u64 i = 0; i < map.size(); ++i)
    {
        for (auto &ch : map[i])
        {
            if (ch == x)
            {
                return '0' + i + 2;
            }
        }
    }
    return ' ';
}

std::string deal(const std::string &str)
{
    std::string res;
    for (const auto &ch : str)
    {
        if (ch == '-')
        {
            continue;
        }
        if (std::isupper(ch))
        {
            res += query(ch);
        }
        else
        {
            res += ch;
        }
    }
    return res.substr(0, 3) + '-' + res.substr(3);
}

void solve()
{
    i32 n;
    std::cin >> n;
    std::unordered_map<std::string, i32> map;
    for (i32 i = 1; i <= n; ++i)
    {
        std::string str;
        std::cin >> str;
        ++map[deal(str)];
    }
    std::vector<std::pair<std::string, i32>> answer;
    for (const auto &[k, v] : map)
    {
        if (v >= 2)
        {
            answer.emplace_back(std::make_pair(k, v));
        }
    }
    std::sort(
        answer.begin(), answer.end(),
        [](const std::pair<std::string, i32> &a, const std::pair<std::string, i32> &b) { return a.first < b.first; });
    bool endl = false;
    for (auto &[k, v] : answer)
    {
        if (endl)
        {
            std::cout << '\n';
        }
        std::cout << k << ' ' << v;
        endl = true;
    }
}
posted @ 2025-10-14 20:12  TPPPP72  阅读(3)  评论(0)    收藏  举报