Rwkj $1359: Two-Point distance

Source: Internet
Author: User
Tags cmath


C ++: youyuan 1 (distance between two points)
Time limit (Common/Java): 1000 ms/3000 Ms running memory limit: 65536 Kbyte
Total submissions: 674 pass the test: 457

Description


Defines the Point class in a two-dimensional plane. The data member in the class is the coordinate of the point, and then defines the membership function dist () to calculate the distance between two points.

Complete the following procedures 1 and 2.

Procedure 1:

# Include <iostream>
# Include <iomanip>
# Include <cmath>
Using namespace STD;
..........................................
..........................................
..........................................
Int main ()
{
Int N;
Double x1, x2, Y1, Y2;
Cin> N;
While (n --)
{
Cin> x1> Y1> X2> Y2;
Point P1 (x1, Y1), P2 (X2, Y2 );
Cout <fixed <setprecision (3) <dist (P1, P2) <Endl;
}
Return 0;
}

 

Procedure 2:

# Include <iostream>
# Include <iomanip>
# Include <cmath>
Using namespace STD;
..........................................
..........................................
..........................................
Int main ()
{Int N; double x1, x2, Y1, Y2; test T;
Cin> N;
While (n --)
{CIN> x1> Y1> X2> Y2;
Point P1 (x1, Y1), P2 (X2, Y2 );
Cout <fixed <setprecision (3) <t. dist (P1, P2) <Endl;
}
}


Input

The input contains N groups of test instances. Row 1st is the number of test groups.

Row 10-row n + 1 test data. Each group of test data has four real numbers, representing the coordinates (x1, Y1) and (X2, Y2) of the two points ).


Output

The distance between two points (retain three decimal places ).

Sample Input

2
0 0 3 4
1 1 2 2


Sample output

5.000
1.414

 

 

 

 

 

 

 

 

# Include <iostream>
# Include <iomanip>
# Include <cmath>
Using namespace STD;
Double distance (INT X1, int Y1, int X2, int Y2)
{
Double S;
S = SQRT (x2-x1) * (x2-x1) + (y2-y1) * (y2-y1 ));
Return S;
}
Int main ()
{
Int x1, x2, Y1, Y2, N;
Double S;
Cin> N;
While (n --)
{
Cin> x1> Y1> X2> Y2;
S = distance (x1, Y1, X2, Y2 );
Cout <setiosflags (IOs: fixed) <setprecision (3) <S <Endl;
}
Return 0;
}

 

 


# Include <iostream>
# Include <iomanip>
# Include <cmath>
Using namespace STD;


Class Point
{
Double X, Y;
Friend double dist (point, point );
Public:
Point (double XX, double YY) {x = xx; y = YY ;}
};

Double dist (point P1, point P2)
{
Return SQRT (p1.x-p2.x) * (p1.x-p2.x) + (p1.y-p2.y) * (p1.y-p2.y ));
}


Int main ()
{
Int N;
Double x1, x2, Y1, Y2;
Cin> N;
While (n --)
{
Cin> x1> Y1> X2> Y2;
Point P1 (x1, Y1), P2 (X2, Y2 );
Cout <fixed <setprecision (3) <dist (P1, P2) <Endl;
}
Return 0;
}

 

 

 

# Include <iostream. h>
# Include <iomanip. h>
# Include <math. h>

Class Point
{
Double X, Y;
Friend double distance (point, point );
Public:
Point (double XX, double YY) {x = xx; y = YY ;}
};

Double distance (point P1, point P2)
{
Return SQRT (p1.x-p2.x) * (p1.x-p2.x) + (p1.y-p2.y) * (p1.y-p2.y ));
}


Int main ()
{
Int N;
Double x1, x2, Y1, Y2;
Cin> N;
While (n --)
{
Cin> x1> Y1> X2> Y2;
Point P1 (x1, Y1), P2 (X2, Y2 );
Cout <fixed <setprecision (3) <distance (P1, P2) <Endl;
}
Return 0;
}

 

 


# Include <iostream. h>
# Include <iomanip. h>
# Include <math. h>

Class Point
{
Double X, Y;

Public:
Double distance (point P)
{Return SQRT (x-p.x) * (x-p.x) + (y-p.y) * (y-p.y ));}

Point (double XX, double YY) {x = xx; y = YY ;}
};

Int main ()
{
Int N;
Double x1, x2, Y1, Y2;
Cin> N;
While (n --)
{
Cin> x1> Y1> X2> Y2;
Point P1 (x1, Y1), P2 (X2, Y2 );
Cout <fixed <setprecision (3) <p1.distance (P2) <Endl;
}
Return 0;
}

 

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.