๐Ÿ”ฅ Algorithm/Baekjoon

[๋ฐฑ์ค€ 3009๋ฒˆ] ๋„ค ๋ฒˆ์งธ ์  - ์ž๋ฐ”์Šคํฌ๋ฆฝํŠธ(nodejs)

Lennon 2022. 1. 25. 22:54
728x90
๋ฐ˜์‘ํ˜•

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

 

3009๋ฒˆ: ๋„ค ๋ฒˆ์งธ ์ 

์„ธ ์ ์ด ์ฃผ์–ด์กŒ์„ ๋•Œ, ์ถ•์— ํ‰ํ–‰ํ•œ ์ง์‚ฌ๊ฐํ˜•์„ ๋งŒ๋“ค๊ธฐ ์œ„ํ•ด์„œ ํ•„์š”ํ•œ ๋„ค ๋ฒˆ์งธ ์ ์„ ์ฐพ๋Š” ํ”„๋กœ๊ทธ๋žจ์„ ์ž‘์„ฑํ•˜์‹œ์˜ค.

www.acmicpc.net

const fs = require('fs');
const input = fs
  .readFileSync('dev/stdin')
  .toString()
  .trim()
  .split('\n')
  .map((v) => v.split(' '));

let x = input.map((v) => v[0]).sort((a, b) => a - b);
let y = input.map((v) => v[1]).sort((a, b) => a - b);

x = x[0] === x[1] ? x[2] : x[0];
y = y[0] === y[1] ? y[2] : y[0];

console.log(x, y);

๊ฐ ์ขŒํ‘œ๋ฅผ ์ •๋ ฌํ•œ ํ›„

๊ฐ ์ขŒํ‘œ์˜ ์ฒซ ๋ฒˆ์งธ์™€ ๋‘ ๋ฒˆ์งธ๊ฐ€ ๊ฐ™์œผ๋ฉด ์„ธ ๋ฒˆ์งธ๋กœ ์ •ํ•ด์ค€๋‹ค.

728x90
๋ฐ˜์‘ํ˜•