whatisthis?
โ๋ฐฑ์ค 14681 javascript (node.js) ํ์ด ๋ณธ๋ฌธ
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() ๋ฉ์๋๋ฅผ ํตํด ์์ฑ ๊ฐ๋ฅ
'ALGORITHM > BOJ (Node.js)' ์นดํ ๊ณ ๋ฆฌ์ ๋ค๋ฅธ ๊ธ
๋ฐฑ์ค 2739 javascript (node.js) ํ์ด (0) | 2021.12.08 |
---|---|
โ๋ฐฑ์ค 2884 javascript (node.js) ํ์ด (0) | 2021.12.06 |
๐บ๋ฐฑ์ค 2753 javascript (node.js) ํ์ด (0) | 2021.12.06 |
๋ฐฑ์ค 9498 javascript (node.js) ํ์ด (0) | 2021.12.06 |
๋ฐฑ์ค 1330 javascript (node.js) ํ์ด (0) | 2021.12.06 |