思路:
水题,略过
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; }