[백준|node.js] 1085번, 직사각형에서 탈출 (Math.min) - 수학

muz·2022년 7월 13일
0
post-thumbnail

✍🏻 문제 확인하기

풀이

let fs = require('fs');
let input = fs.readFileSync('/dev/stdin').toString().split(" ");
const x = Number(input[0]);
const y = Number(input[1]);
const w = Number(input[2]);
const h = Number(input[3]);

const array = [x, w-x, y, h-y];
const answer = Math.min(...array);
console.log(answer);

해설

  • (x,y)에서 경계선까지 가는 거리의 최솟값은 그냥 x, y, w-x, h-y를 구하고 그 중 최솟값을 출력하면 된다.
profile
Life is what i make up it 💨

0개의 댓글