2021团体程序设计天梯赛 L2-3 清点代码库

思路:

水题,略过

Tip:

#include <bits/stdc++.h>

using namespace std;

const int maxn = 10000 + 5;
int n, m;

struct mmp {
    int a[105];
    int cnt = 0;
} member[maxn];

bool cmp(mmp a, mmp b) {
    if (a.cnt == b.cnt) {
        bool flag = false;
        for (int i = 0; i < m; i++)
            if (a.a[i] != b.a[i])
                return a.a[i] < b.a[i];
    }
    return a.cnt > b.cnt;
}

map<vector<int>, int> mp;

int main() {
    cin >> n >> m;
    int cnt = 0;
    for (int i = 1; i <= n; i++) {
        vector<int> v;
        for (int j = 0; j < m; j++) {
            int tmp;
            cin >> tmp;
            v.push_back(tmp);
        }
        if (mp.find(v) == mp.end()) {
            mp[v] = cnt;
            for (int j = 0; j < m; j++)
                member[cnt].a[j] = v[j];
            member[cnt].cnt = 1;
            cnt++;
        } else {
            int nop = mp[v];
            member[nop].cnt++;
        }
    }
    sort(member, member + cnt, cmp);
    cout << cnt << endl;
    for (int i = 0; i < cnt; i++) {
        cout << member[i].cnt;
        for (int j = 0; j < m; j++)
            cout << " " << member[i].a[j];
        cout << endl;
    }
    return 0;
}

  

上一篇:混合云下的 Kubernetes 多集群管理与应用部署


下一篇:Redis的数据类型 - zset 基本操作