0
点赞
收藏
分享

微信扫一扫

L2-039 清点代码库

沈芏 2022-03-11 阅读 35

题目

在这里插入图片描述

代码

#include <bits/stdc++.h>
using namespace std;
int n, m;
unordered_map<string, int> mp;
vector<pair<int, vector<int>>> ans;
int main() {
    cin >> n >> m;
    getchar();
    for (int i = 1; i <= n; ++ i) {
        string ve;
        getline(cin, ve);
        mp[ve] ++;
    }
    for (auto& [x, y] : mp) {
        stringstream os(x);
        vector<int> tm(m);
        for (int i = 0; i < m; ++ i)
            os >> tm[i];
        ans.emplace_back(y, tm);
    }
    sort (ans.begin(), ans.end(), [](auto& a, auto& b) {
        #define x first
        #define y second
        if (a.x == b.x) {
            auto &x = a.y;
            auto &y = b.y;
            for (int i = 0; i < min (x.size(), y.size()); ++ i) 
                if (x[i] != y[i]) return x[i] < y[i];
            return x.size() < y.size();
        }
        return a.x > b.x;
    });
    cout << ans.size() << endl;
    for (auto& [x, y] : ans) {
        cout << x;
        for (auto& t : y) 
            cout << " " << t;
        cout << endl;
    }
    return 0;
}
举报

相关推荐

0 条评论