whatisthis?

βŒλ°±μ€€ 14681 javascript (node.js) 풀이 λ³Έλ¬Έ

ALGORITHM/BOJ (Node.js)

βŒλ°±μ€€ 14681 javascript (node.js) 풀이

thisisyjin 2021. 12. 6. 14:52

if문 - (4)

 

 


 

πŸ’‘λ¬Έμ œ

ν”ν•œ μˆ˜ν•™ 문제 쀑 ν•˜λ‚˜λŠ” 주어진 점이 μ–΄λŠ 사뢄면에 μ†ν•˜λŠ”μ§€ μ•Œμ•„λ‚΄λŠ” 것이닀. 사뢄면은 μ•„λž˜ 그림처럼 1λΆ€ν„° 4κΉŒμ§€ 번호λ₯Ό κ°–λŠ”λ‹€. "Quadrant n"은 "제n사뢄면"μ΄λΌλŠ” λœ»μ΄λ‹€.

예λ₯Ό λ“€μ–΄, μ’Œν‘œκ°€ (12, 5)인 점 AλŠ” xμ’Œν‘œμ™€ yμ’Œν‘œκ°€ λͺ¨λ‘ μ–‘μˆ˜μ΄λ―€λ‘œ 제1사뢄면에 μ†ν•œλ‹€. 점 BλŠ” xμ’Œν‘œκ°€ 음수이고 yμ’Œν‘œκ°€ μ–‘μˆ˜μ΄λ―€λ‘œ 제2사뢄면에 μ†ν•œλ‹€.

점의 μ’Œν‘œλ₯Ό μž…λ ₯λ°›μ•„ κ·Έ 점이 μ–΄λŠ 사뢄면에 μ†ν•˜λŠ”μ§€ μ•Œμ•„λ‚΄λŠ” ν”„λ‘œκ·Έλž¨μ„ μž‘μ„±ν•˜μ‹œμ˜€. 단, xμ’Œν‘œμ™€ yμ’Œν‘œλŠ” λͺ¨λ‘ μ–‘μˆ˜λ‚˜ 음수라고 κ°€μ •ν•œλ‹€.

 

πŸ“μž…λ ₯

첫 μ€„μ—λŠ” μ •μˆ˜ xκ°€ 주어진닀. (−1000 ≤ x ≤ 1000; x ≠ 0) λ‹€μŒ μ€„μ—λŠ” μ •μˆ˜ yκ°€ 주어진닀. (−1000 ≤ y ≤ 1000; y ≠ 0)

 

πŸ“ˆμΆœλ ₯

점 (x, y)의 사뢄면 번호(1, 2, 3, 4 쀑 ν•˜λ‚˜)λ₯Ό 좜λ ₯ν•œλ‹€.

 


< μ½”λ“œ >

 

const readline = require("readline");
const rl = readline.createInterface({
  input: process.stdin,
  output: process.stdout
});

let input = [];

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) {
    console.log(1);
  } else if (x < 0 && y > 0) {
    console.log(2);
  } else if (x < 0 && y < 0) {
    console.log(3);
  } else if (x > 0 && y < 0) {
    console.log(4);
  }
  process.exit();
});

 


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

const x = parseInt(input[0]);
const y = parseInt(input[1]);


if(x > 0 && y > 0) {
   console.log(1);
} else if (x < 0 && y > 0) {
   console.log(2);
} else if (x < 0 && y < 0) {
   console.log(3);
} else {
   console.log(4);
}

μ²˜μŒμ— μ›λž˜ ν•˜λ˜λŒ€λ‘œ fs λͺ¨λ“ˆμ„ μ΄μš©ν–ˆλ”λ‹ˆ

λŸ°νƒ€μž„ μ—λŸ¬ (EACCES)

μ—λŸ¬κ°€ λ°œμƒν–ˆλ‹€.

 

 

이게 뭐지 μ‹Άμ–΄μ„œ ꡬ글링 ν•΄λ³΄λ‹ˆ λ‹€ν–‰νžˆ λ„ˆλ¬΄λ‚˜λ„ μΉœμ ˆν•œ 글을 λ°œκ²¬ν–ˆλ‹€!

 

https://hanch-dev.tistory.com/4

 

[λ°±μ€€] Node.js μ•Œκ³ λ¦¬μ¦˜ ν’€λ•Œ 주의 사항

21-06-04 μ—…λ°μ΄νŠΈ 이 글은 μ œκ°€ 문제λ₯Ό ν’€λ‹€κ°€ 좔가적인 μ£Όμ˜μ μ„ λ°œκ²¬ν™œ 경우 μ§€μ†μ μœΌλ‘œ 좔가될 μ˜ˆμ •μž…λ‹ˆλ‹€. μ €λŠ” κ·Έλ‚˜λ§ˆ μžμ‹ μžˆλŠ” μ–Έμ–΄κ°€ JavaScriptμ—¬μ„œ μ•Œκ³ λ¦¬μ¦˜ μ‚¬μ΄νŠΈμ—μ„œλŠ” 주둜 Node.js, JavaS

hanch-dev.tistory.com

fsλͺ¨λ“ˆμ€ μ˜ˆμ œ μž…λ ₯ νŒŒμΌμ— μ ‘κ·Όν•΄μ•Ό ν•˜κΈ° λ•Œλ¬Έμ—
일뢀 λ¬Έμ œμ—μ„œλŠ” "λŸ°νƒ€μž„ μ—λŸ¬ (EACCES)" ν˜•νƒœμ˜ μ ‘κ·ΌκΆŒν•œ 였λ₯˜κ°€ λ‚˜νƒ€λ‚˜κ³ ,

μ΄λŸ΄λ•ŒλŠ” readline을 μ¨μ•Όν•œλ‹€κ³  ν•œλ‹€!

 

 

// 예제 μž…λ ₯이 ν•œμ€„λ‘œ λ˜μ–΄ μžˆμ„ λ•Œ
const readline = require('readline');

const rl = readline.createInterface({
  input: process.stdin,
  output: process.stdout
});

rl.on('line', function(line) {
  console.log(line);

  rl.close();
}).on("close", function() {
  process.exit();
});

-----------------------------------------

// 예제 μž…λ ₯이 μ—¬λŸ¬μ€„λ‘œ λ˜μ–΄ μžˆμ„ λ–Ό
const readline = require('readline');

const rl = readline.createInterface({
  input: process.stdin,
  output: process.stdout
});

let input = [];

rl.on('line', function (line) {
  input.push(line)
})
  .on('close', function () {
  console.log(input);
  process.exit();
});


좜처: https://hanch-dev.tistory.com/4 [HanCh_Dev]

 

 

 

readline에 λŒ€ν•œ λ‚΄μš©μ€ μ•„λž˜ ν¬μŠ€νŒ…μ—μ„œ λ”°λ‘œ 닀루도둝 ν•˜κ² λ‹€. 

 

πŸ”»πŸ”»πŸ”»πŸ”»πŸ”»πŸ”»πŸ”»

 

https://mywebproject.tistory.com/182

 

javaScript(Node.js). readlineκ³Ό fsλͺ¨λ“ˆ

readlineκ³Ό fsλͺ¨λ“ˆ 1. fsλͺ¨λ“ˆ μ‚¬μš©μ‹œ const fs = require('fs'); const input = fs.readFileSync('/dev/stdin').toString().split(' '); // const input = require('fs').readFileSync('/dev/stdin').toString()...

mywebproject.tistory.com

 

readline.createInterface() λ©”μ˜λ“œλ₯Ό 톡해 생성 κ°€λŠ₯