#include <iostream>
#include <vector>
struct Point {
double x, y;
};
int main() {
std::vector<Point> points = {{1, 1}, {2, 1}, {2, 3}, {1, 2}};
// 初始化最小的两个 x 坐标值
double min_x1 = std::numeric_limits<double>::infinity();
double min_x2 = std::numeric_limits<double>::infinity();
// 初始化对应的两个点
Point closestPoint1, closestPoint2;
for (const auto& point : points) {
if (point.x < min_x1) {
// 更新最小的 x 坐标值和对应的点
min_x2 = min_x1;
closestPoint2 = closestPoint1;
min_x1 = point.x;
closestPoint1 = point;
} else if (point.x < min_x2) {
// 更新次小的 x 坐标值和对应的点
min_x2 = point.x;
closestPoint2 = point;
}
}
// 输出靠 x 轴最近的两个点
std::cout << "最近的坐标点: (" << closestPoint1.x << ", " << closestPoint1.y << ")" << std::endl;
std::cout << "次近的坐标点: (" << closestPoint2.x << ", " << closestPoint2.y << ")" << std::endl;
return 0;
}