给定以下Point类,为其定义小于符号的操作符重载,使得我们可以用std::sort来对vector<Point>进行从小到大的排序(先按x从小到大排,然后按照y从小到大排),确保以下代码成功运行:
#include <iostream>
#include <vector>
#include <algorithm>
struct Point {
int x;
int y;
};
int main() {
int x = 0;
int y = 0;
std::vector<Point> vec;
while (std::cin >> x >> y) {
Point p;
p.x = x;
p.y = y;
vec.push_back(p);
}
std::sort(vec.begin(), vec.end());
for (auto iter = vec.begin(); iter != vec.end(); ++iter) {
std::cout << iter->x << " " << iter->y << std::endl;
}
return 0;
}