题解 | #点的距离#
点的距离
https://www.nowcoder.com/practice/3468bd027c5a410e895150b0d5b13502
#include <iostream> #include <cmath> #include <iomanip> using namespace std; class CPoint { private: int x, y; public: CPoint(int x, int y) : x(x), y(y) {} float operator-(const CPoint &other) const { return sqrt(pow(x - other.x, 2) + pow(y - other.y, 2)); } }; int main() { int m; cin >> m; while (m--) { int x1, y1, x2, y2; cin >> x1 >> y1 >> x2 >> y2; CPoint p1(x1, y1), p2(x2, y2); cout << fixed << setprecision(2) << p1 - p2 << endl; } return 0; }