Dễ 0 đã giải Tỷ lệ chấp nhận 0%

Distance Between Points

Compute the straight-line distance between two points.

Đề bài

Compute the Euclidean distance between (x1, y1) and (x2, y2): the square root of (x2 − x1)² + (y2 − y1)².

Implement distance(x1, y1, x2, y2).

Input

x1: First point x. y1: First point y. x2: Second point x. y2: Second point y.

Output

Return the distance.

Ràng buộc

-1,000,000 ≤ each coordinate ≤ 1,000,000

Ví dụ

Ví dụ 1
Đầu vào:
x1 = 0.0
x2 = 3.0
y1 = 0.0
y2 = 4.0

Kết quả mong đợi:
expected = 5.0
Đầu vào:
double x1 = 0.0;
double x2 = 3.0;
double y1 = 0.0;
double y2 = 4.0;

Kết quả mong đợi:
double expected = 5.0;
Đầu vào:
double x1 = 0.0;
double x2 = 3.0;
double y1 = 0.0;
double y2 = 4.0;

Kết quả mong đợi:
double expected = 5.0;

Giải thích

√(3² + 4²) = √25 = 5.

Ví dụ 2
Đầu vào:
x1 = 1.0
x2 = 1.0
y1 = 1.0
y2 = 1.0

Kết quả mong đợi:
expected = 0.0
Đầu vào:
double x1 = 1.0;
double x2 = 1.0;
double y1 = 1.0;
double y2 = 1.0;

Kết quả mong đợi:
double expected = 0.0;
Đầu vào:
double x1 = 1.0;
double x2 = 1.0;
double y1 = 1.0;
double y2 = 1.0;

Kết quả mong đợi:
double expected = 0.0;

Giải thích

Both points are the same, so the distance is 0.

Tham khảo

Thử thách này đã được điều chỉnh cho CodeUtility. Hãy làm theo đề bài và các ràng buộc ở trên.

Học hỏi từ người khác

Giải pháp cộng đồng

Chưa có giải pháp nào được chia sẻ. Hãy giải thử thách này để đăng giải pháp đầu tiên.