PTA清点代码库

一、题目描述

 

 二、解题思路

  利用map,vector进行映射,然后读出来就可以了,本题是一个stl的妙用。

三、代码实现

 1 #include "bits/stdc++.h"
 2 using namespace std;
 3 map <vector<int>,int> mp;
 4 int main()
 5 {
 6     int n,m;
 7     ios::sync_with_stdio(false);
 8     cin >> n >> m;
 9     for(int i = 1;i <= n;i++){
10         vector <int> tmp;
11         for(int j = 1;j <= m;j++){
12             int x;
13             cin >> x;
14             tmp.push_back(x);
15         }
16         mp[tmp]++;
17     }
18     vector <pair<int,vector<int>>> ans;
19     for(auto &u:mp)
20         ans.push_back({-u.second,u.first});
21     sort(ans.begin(),ans.end());
22     cout << ans.size() << endl;
23     for(auto v:ans){
24         cout << abs(v.first);
25         for(auto u:v.second)
26             cout << ' ' << u;
27         cout << endl;
28     }
29     return 0;
30 }
posted @ 2022-03-19 15:12  scannerkk  阅读(189)  评论(0)    收藏  举报