两点距离
时间限制:
3000 ms | 内存限制:
65535 KB
难度:
1
-
描述
-
输入两点坐标(X1,Y1),(X2,Y2)(0<=x1,x2,y1,y2<=1000),计算并输出两点间的距离。
问题链接:http://acm.nyist.net/JudgeOnline/problem.php?pid=101
代码:
#include <iostream>
#include <stdio.h>
#include <string.h>
#include <math.h>
#include <vector>
#include <queue>
#include <stack>
#include <map>
#include <string>
#include <algorithm>
using namespace std;
/* run this program using the console pauser or add your own getch, system("pause") or input loop */
struct Point{
double x;
double y;
double distance(Point p){
return sqrt((x-p.x)*(x-p.x)+(y-p.y)*(y-p.y));
}
};
int main(int argc, char** argv) {
int n;
scanf("%d",&n);
while(n--){
Point a,b;
scanf("%lf%lf%lf%lf",&a.x,&a.y,&b.x,&b.y);
printf("%0.2lf\n",a.distance(b));
}
return 0;
}