-
<백준> 14681번: 사분면 고르기유물/└ 백준 2021. 12. 25. 16:15728x90
🤖
문제
https://www.acmicpc.net/problem/14681
풀이
const readline = require("readline"); const rl = readline.createInterface({ input: process.stdin, output: process.stdout, }); let input = []; let quadrantVal; rl.on("line", function (line) { input.push(parseInt(line)); }).on("close", function () { const x = input[0]; const y = input[1]; if (x > 0) { y > 0 ? (quadrantVal = 1) : (quadrantVal = 4); } else { y > 0 ? (quadrantVal = 2) : (quadrantVal = 3); } console.log(quadrantVal); process.exit(); });
1. (공통) 문제에서 주어진 input값을 받으려면 fs 대신 readline을 써야 합니다.
2. (line) 17, 19) 간단한 계산이기 때문에 삼항 연산자를 활용하여 함축적인 코드로 작성하였습니다.
📌
https://velog.io/@dragoocho/%EB%B0%B1%EC%A4%80-14681%EB%B2%88-JavaScript
https://tesseractjh.tistory.com/39?category=473836
728x90'유물 > └ 백준' 카테고리의 다른 글
<백준> 2739번: 구구단 (0) 2021.12.27 <백준> 2884번: 알람 시계 (0) 2021.12.25 <백준> 2753번: 윤년 (0) 2021.12.23 <백준> 9498번: 시험 성적 (0) 2021.12.23 <백준> 1330번: 두 수 비교하기 (0) 2021.12.21