两点距离

两点距离

时间限制: 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
来源
[苗栋栋]原创
上传者
苗栋栋

问题链接: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;
}


  •                  
  •                  
  •                 
    • 0
      点赞
    • 1
      收藏
      觉得还不错? 一键收藏
    • 0
      评论
    评论
    添加红包

    请填写红包祝福语或标题

    红包个数最小为10个

    红包金额最低5元

    当前余额3.43前往充值 >
    需支付:10.00
    成就一亿技术人!
    领取后你会自动成为博主和红包主的粉丝 规则
    hope_wisdom
    发出的红包
    实付
    使用余额支付
    点击重新获取
    扫码支付
    钱包余额 0

    抵扣说明:

    1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
    2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

    余额充值