二维数组排序
作者:
半醒的狐狸
,
2022-08-28 20:17:52
,
所有人可见
,
阅读 247
二维数组排序
#include <algorithm>
#include <iostream>
#include <vector>
using namespace std;
bool cmp(vector<int> a, vector<int> b)
{
if(a[0] != b[0]) return a[0] > b[0]; // a[0]排序
if(a[1] != b[1]) return a[1] > b[1]; // a[1]排序
if(a[2] != b[2]) return a[2] > b[2]; // a[2]排序
}
int main()
{
vector<vector<int>> vec = { {1,4,3}, {1,4,7} , {1,3,5} , {2,9,4} , {2,5,8} , {3,9,6} };
sort(vec.begin(), vec.end(), cmp);
for(auto p : vec)
cout<<p[0]<<' '<<p[1]<<' '<<p[2]<<endl;
return 0;
}