๋ณธ๋ฌธ ๋ฐ”๋กœ๊ฐ€๊ธฐ

ํ”„์—” ๊ณต๋ถ€/๐Ÿซง ์•Œ๊ณ ๋ฆฌ์ฆ˜ ๊ณต๋ถ€

[๋ฐฑ์ค€/Node.js] 10951๋ฒˆ ํ’€์ด || JavaScript

728x90
let input = require('fs').readFileSync('/dev/stdin').toString().trim().split("\n");
for (let i = 0; i <= input.length - 1; i++) {
    let nums = input[i].split(" ");
    console.log(Number(nums[0]) + Number(nums[1]));
}

๐ŸŸ ๊ฐ€์žฅ ์œ—์ค„์—์„œ ํŒŒ์ผ์„ ๋ฐ›์•„์˜ฌ ๋•Œ trim() ์ž‘์—…์„ ํ•ด์ค€ ํ›„ ๊ฐ ์ค„๋กœ ๋‚˜๋ˆ ์ฃผ๋Š” split("\n")์„ ํ•ด์ค˜์•ผํ•œ๋‹ค.

์•ˆ๊ทธ๋Ÿฌ๋ฉด 

1 1
2 3
3 4
9 8
5 2
1 9
๋น„์–ด์žˆ๋Š” ๋ผ์ธ

์š” ๊ฒฝ์šฐ์— ๋งˆ์ง€๋ง‰ ์ค„์ด NaN์ด ์ถœ๋ ฅ๋˜๊ธฐ ๋•Œ๋ฌธ์— ํ‹€๋ ธ๋‹ค๊ณ  ๋‚˜์˜จ๋‹ค. 

 

 ๐ŸŸ for ๋ฌธ์˜ ๋งˆ์ง€๋ง‰ ๋ฃจํ”„๋Š” ๋ฐ›์•„์˜จ input lenght์—์„œ -1์„ ํ•ด์ค˜์•ผํ•œ๋‹ค.

 

๋ฐ˜๋ณต๋ฌธ๋„ ๋...!!

728x90
๋ฐ˜์‘ํ˜•