赞
踩
这里直接把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;; }
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。