兩點距離
兩點距離
時間限製:3000 ms | 內存限製:65535 KB
難度:1
- 描述
-
輸入兩點坐標(X1,Y1),(X2,Y2)(0<=x1,x2,y1,y2<=1000),計算並輸出兩點間的距離。
- 輸入
- 第一行輸入一個整數n(0<n<=1000),表示有n組測試數據;
隨後每組占一行,由4個實數組成,分別表示x1,y1,x2,y2,數據之間用空格隔開。 - 輸出
- 對於每組輸入數據,輸出一行,結果保留兩位小數。
- 樣例輸入
-
2 0 0 0 1 0 1 1 0 - 樣例輸出
-
1.00 1.41
#include <iostream>
02.#include <cstdio>03.#include <cmath>04.using
namespace std;05. 06.int
main()07.{08.int
testNum;09.cin >> testNum;10.while
(testNum--)11.{12.double
x1, x2, y1, y2;13.cin >> x1 >> y1 >> x2 >> y2;14.x1 -= x2;15.y1 -= y2;16.x1 *= x1;17.y1 *= y1;18.y1 += x1;19.printf("%.2lf\n",
sqrt(y1));20.}21. 22.return
0;23.}最後更新:2017-04-02 15:14:53