2017.10.12

两点距离

时间限制: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>
#include <stdio.h>
#include <math.h>
#include <iomanip> //不能写成#include <iomanip.h>
using namespace std;
/* run this program using the console pauser or add your own getch, system("pause") or input loop */

int main(int argc, char** argv)
{
int n=0;
float x1_array[1000];
float y1_array[1000];
float x2_array[1000];
float y2_array[1000];
float dis=0.0;
cin>>n;
// cout<<n<<endl;
for(int i=0;i<n;i++)
{
cin>>x1_array[i]>>y1_array[i]>>x2_array[i]>>y2_array[i];
}
for(int j=0;j<n;j++)
{
dis=sqrt(pow((x1_array[j]-x2_array[j]),2)+pow((y1_array[j]-y2_array[j]),2));
cout<<fixed<<setprecision(2)<<dis<<endl; //保留两位小数输出
dis=0.0;
}

return 0;
}


原文地址:https://www.cnblogs.com/panlangen/p/7732784.html