728x90

https://www.acmicpc.net/problem/3009

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}`);

+ Recent posts