# [Algorithm/JS] ๋ฐฑ์ค€ 10951๋ฒˆ A+B - 4

๐Ÿ”— ๋ฌธ์ œ ๋ฐ”๋กœ๊ฐ€๊ธฐ (opens new window)

# Question

๋‘ ์ •์ˆ˜ A์™€ B๋ฅผ ์ž…๋ ฅ๋ฐ›์€ ๋‹ค์Œ, A+B๋ฅผ ์ถœ๋ ฅํ•˜๋Š” ํ”„๋กœ๊ทธ๋žจ์„ ์ž‘์„ฑํ•˜์‹œ์˜ค.

# Input

์ž…๋ ฅ์€ ์—ฌ๋Ÿฌ ๊ฐœ์˜ ํ…Œ์ŠคํŠธ ์ผ€์ด์Šค๋กœ ์ด๋ฃจ์–ด์ ธ ์žˆ๋‹ค.

๊ฐ ํ…Œ์ŠคํŠธ ์ผ€์ด์Šค๋Š” ํ•œ ์ค„๋กœ ์ด๋ฃจ์–ด์ ธ ์žˆ์œผ๋ฉฐ, ๊ฐ ์ค„์— A์™€ B๊ฐ€ ์ฃผ์–ด์ง„๋‹ค. (0 < A, B < 10)

# Output

๊ฐ ํ…Œ์ŠคํŠธ ์ผ€์ด์Šค๋งˆ๋‹ค A+B๋ฅผ ์ถœ๋ ฅํ•œ๋‹ค.

# Example

# Input

1 1
2 3
3 4
9 8
5 2
1
2
3
4
5

# Output

2
5
7
17
7
1
2
3
4
5

# Solution

๋‚˜์˜ ํ’€์ด๋Š” ์•„๋ž˜์™€ ๊ฐ™๋‹ค.

const input = require('fs').readFileSync('dev/stdin').toString().split('\n');
let i = 0;
let result = '';
while (i < input.length) {
  const [a, b] = input[i].split(' ').map(Number);
  result += `${a + b}\n`;
  i++;
}
console.log(result);
1
2
3
4
5
6
7
8
9

์ œ์ถœ๊ฒฐ๊ณผ ๋‹ต์ด ํ‹€๋ ธ๋‹ค๊ณ  ๋‚˜์˜จ๋‹ค. ์•„๋ฌด๋ฆฌ ๋ด๋„ ํ‹€๋ฆฐ ๋ถ€๋ถ„์„ ๋ชจ๋ฅด๊ฒ ๋‹ค. ๊ทธ๋ž˜์„œ while ๋ถ€๋ถ„์—input.length-1 ๋ฅผ ์กฐ๊ฑด์œผ๋กœ ์ฃผ์—ˆ๋‹ค. ์ด๋ ‡๊ฒŒ ์ž‘์„ฑํ•˜๋ฉด ๋งˆ์ง€๋ง‰ ์ค„์€ ์ถœ๋ ฅํ•˜์ง€ ์•Š๋Š”๋‹ค. ๊ทผ๋ฐ ์ด๊ฒŒ ์ด๋Œ€๋กœ ์ œ์ถœํ•˜๋ฉด ์ •๋‹ต์ด๋ผ๊ณ  ํ•œ๋‹ค. ์ดํ•ด๊ฐ€ ๊ฐ€์ง€ ์•Š๋Š”๋‹ค.. ๋ฌธ์ œ์— ์ œ์‹œ๋œ Output๊ณผ ๊ฒฐ๊ณผ๊ฐ€ ๋‹ค๋ฅธ๋ฐ ์ •๋‹ต์ด๋ผ๊ณ  ํ•œ๋‹ค..? ๋ฌธ์ œ๊ฐ€ ์ด์ƒํ•˜๋‹ค..ใ…œ

const input = require('fs').readFileSync('dev/stdin').toString().split('\n');
let i = 0;
let result = '';
while (i < input.length - 1) {
  const [a, b] = input[i].split(' ').map(Number);
  result += `${a + b}\n`;
  i++;
}
console.log(result);
1
2
3
4
5
6
7
8
9
Last Updated: 2022. 6. 5. ์˜คํ›„ 3:42:39