Written by
nodejs-style
on
on
[백준/nodejs/1085] 직사각형에서 탈출 javascript
[백준/nodejs/1085] 직사각형에서 탈출 javascript
(0,0) 과 (w,h) 에 꼭짓점이 있고 주어진 (x,y)좌표에서 가장 가까운 거리를 가진 거리를 제출하면 된다.
let fs = require('fs'); let input = fs.readFileSync('/dev/stdin').toString().split(' '); const [x,y,w,h] = input; let res = []; res.push(x) res.push(y) res.push(Math.abs(x-w)) res.push(Math.abs(y-h)) console.log(Math.min(...res))
x,y,w,h를 구조분해할당으로 각각 받아서
x-0 , y-0, x-w, y-h 중 가장 작은 값을 찾으면 됨.
from http://pannchat.tistory.com/124 by ccl(A) rewrite - 2021-08-11 13:00:26