# [Algorithm/JS] 백준 3009번 네 번째 점

🔗 문제 바로가기 (opens new window)

# Question

세 점이 주어졌을 때, 축에 평행한 직사각형을 만들기 위해서 필요한 네 번째 점을 찾는 프로그램을 작성하시오.

# Input

세 점의 좌표가 한 줄에 하나씩 주어진다. 좌표는 1보다 크거나 같고, 1000보다 작거나 같은 정수이다.

# Output

직사각형의 네 번째 점의 좌표를 출력한다.

# Example

# Input 1

5 5
5 7
7 5
1
2
3

# Output 1

7 7
1

# Input 2

30 20
10 10
10 20
1
2
3

# Output 2

30 20
10 10
10 20
1
2
3

# Solution

const fs = require('fs');
const input = fs.readFileSync('dev/stdin').toString().trim().split(/\s+/).map(Number);

const x = input.filter((v, i) => i % 2 === 0);
const y = input.filter((v, i) => i % 2 !== 0);

console.log(findCoord(x), findCoord(y));

function findCoord(coord) {
  return coord[0] === coord[1] ? coord[2] : coord[1] === coord[2] ? coord[0] : coord[1];
}
1
2
3
4
5
6
7
8
9
10
11

각 x, y 를 비교해 좌표를 찾아냈다.

Last Updated: 2022. 6. 5. 오후 3:42:39