728x90

Code

😢 이쁘게 풀어주려다가 그냥 조건문으로 끝낸 문제
😊 가끔은 단순한게 좋은 방법인듯 하다.
일단 x좌표가 같은 것이 있다면, 이미 평행한 좌표가 있는 것이고
y좌표가 같은 것이 있다면, 역시 평행한 좌표가 있는 것이다.
따라서, x 또는 y가 한 번만 존재하는 좌표를 찾아내고 그 값을 넣어주면 된다.
Full Code (https://github.com/DasolPark/Dasol_JS_Algorithm/tree/master/Baekjoon)
| // Fourth coordinate(in a rectangle) |
| // For submit |
| // const fs = require('fs'); |
| // const input = fs.readFileSync('/dev/stdin').toString().trim().split('\n'); |
| // For local test |
| const input = ['30 20', '10 10', '10 20']; |
| const strToInt = input.map(coords => |
| coords.split(' ').map(num => parseInt(num)) |
| ); |
| let x = 0; |
| let y = 0; |
| if (strToInt[0][0] !== strToInt[1][0]) { |
| if (strToInt[0][0] !== strToInt[2][0]) { |
| x = strToInt[0][0]; |
| } else { |
| x = strToInt[1][0]; |
| } |
| } else { |
| x = strToInt[2][0]; |
| } |
| if (strToInt[0][1] !== strToInt[1][1]) { |
| if (strToInt[0][1] !== strToInt[2][1]) { |
| y = strToInt[0][1]; |
| } else { |
| y = strToInt[1][1]; |
| } |
| } else { |
| y = strToInt[2][1]; |
| } |
| console.log(`${x} ${y}`); |
'Algorithm > JavaScript(Node.js)' 카테고리의 다른 글
| 백준 1002번: 터렛 Node.js(JavaScript) (0) | 2020.01.28 |
|---|---|
| 백준 3053번: 택시 기하학(유클리드 기하학) Node.js(JavaScript) (0) | 2020.01.28 |
| 백준 4153번: 직각삼각형(피타고라스의 정리) Node.js(JavaScript) (0) | 2020.01.27 |
| 백준 1085번: 직사각형에서 탈출 Node.js(JavaScript) (0) | 2020.01.25 |
| 백준 9020번: 소수 구하기(골드바흐의 추측 - 에라토스테네스의 체) Node.js(JavaScript) (0) | 2020.01.24 |