Manhattan Distance (M.D.) between two points A(x1, y1) and B(x2, y2) is defined as follows: M.D. =
Fantastic news! We've Found the answer you've been seeking!
Question:
Manhattan Distance (M.D.) between two points A(x1, y1) and B(x2, y2) is defined as follows:
M.D. = |x1 - x2| + |y1 - y2|
Write down a structure that will model a point in 2-dimensional space. Using the above structure take input of two locations and calculate Manhattan distance between them.
Input Format
The input contains four floating point values in the following format:
x1 y1
x2 y2
Constraints
Output Format
Print a single floating point number, with two places after the decimal point, denoting the Manhattan Distance between (x1, y1) and (x2, y2) as shown in the sample output.
Sample Input 0
5 41 1
Sample Output 0
Manhattan Distance = 7.00
Explanation 0
x1 = 5, y1 = 4 x2 = 1, y2 = 1 |x1 - x2| + |y1 - y2| = |5-1| + |4-1| = |4| + |3| = 4 + 3 = 7.00
Sample Input 1
-100 9.87100 0.12
Sample Output 1
Manhattan Distance = 209.75
Related Book For
Posted Date: