mySQL

[HackerRank] Weather Observation Station 18

bellhundred 2023. 2. 26. 12:58

https://www.hackerrank.com/challenges/weather-observation-station-18/problem?isFullScreen=true&h_r=next-challenge&h_v=zen&h_r=next-challenge&h_v=zen&h_r=next-challenge&h_v=zen&h_r=next-challenge&h_v=zen&h_r=next-challenge&h_v=zen&h_r=next-challenge&h_v=zen 

 

Weather Observation Station 18 | HackerRank

Query the Manhattan Distance between two points, round or truncate to 4 decimal digits.

www.hackerrank.com

SELECT ROUND(ABS(MIN(LAT_N)-MAX(LAT_N))+ABS(MIN(LONG_W)-MAX(LONG_W)),4)
FROM STATION

Manhattan distance

Definition: The distance between two points measured along axes at right angles. In a plane with p1 at (x1, y1) and p2 at (x2, y2),

 

it is |x1 - x2| + |y1 - y2|.

 

공식을 보고 그대로 작성하면 된다. 절대값은 ABS 로 표기할 수 있으며 반올림은 ROUND로 사용한다. 뒤의 숫자 4는 반올림 시 표기할 소수점의 자리수를 나타낸다.(소수점 아래 5째자리에서 반올림한다는 이야기.)