不得不说,人家的代码真不错
c++容器 set 自定义排序_zhusf的博客-CSDN博客_c++set排序
#include <bits/stdc++.h>
using namespace std;
const int N = 1e4+10;
struct cmp//自定义set排序
{
bool operator() (const pair<int,vector<int> >&a, const pair<int,vector<int> >&b) const
{
if(a.first!=b.first)
return a.first>b.first;
else return a.second<b.second;
}
};
set<vector<int> > st;//存模块
map<vector<int>,int> mp;//存每个模块的个数
set<pair<int,vector<int> >,cmp > St;//排序
int main()
{
int n,m;
cin>>n>>m;
for(int i=0; i<n; i++)
{
vector<int> vt;
for(int j=0; j<m; j++)
{
int x;
cin>>x;
vt.push_back(x);
}
mp[vt]++;
st.insert(vt);
}
cout<<st.size()<<endl;
set<vector<int> >::iterator it;
for(it=st.begin(); it!=st.end(); it++)
{
St.insert({mp[*it],*it});
}
set<pair<int,vector<int> > >::iterator ite;
for(ite=St.begin(); ite!=St.end(); ite++)
{
cout<<(*ite).first;
for(int i=0; i<(*ite).second.size(); i++)
cout<<' '<<(*ite).second[i];
cout<<endl;
}
return 0;
}