题目
思路
这里直接把x和y换一下输入然后排序就完事了。。
代码
#include<bits/stdc++.h>
#include<algorithm>
using namespace std;
struct ele
{
int x;
int y;
int d;
};
bool cmp(ele a, ele b)
{
if(a.x == b.x)
return (a.y < b.y);
return(a.x < b.x);
}
int main()
{
int row, col, n;
cin >> row >> col >> n;
ele* metrix = new ele[n];
for(int i = 0; i < n; i++)
{
cin >> metrix[i].y >> metrix[i].x >> metrix[i].d;
}
sort(metrix, metrix + n, cmp);
for(int i = 0; i < n; i++)
cout << metrix[i].x <<" "<< metrix[i].y <<" "<< metrix[i].d << endl;;
}