26545๋ฒ: Mathematics
A mathematician has stolen your calculator! Luckily, you know how to code and can write a program that adds together numbers. Write a program that adds together a list of integers.
www.acmicpc.net
๋ฌธ์
A mathematician has stolen your calculator! Luckily, you know how to code and can write a program that adds together numbers. Write a program that adds together a list of integers.
์ ๋ ฅ
The first line will contain a single integer n that indicates the number of integers to add together. The next n lines will each contain one integer. Your task is to write a program that adds all of the integers together.
์ถ๋ ฅ
Output the resulting integer. The output should be one line containing one integer value.
ํ์ด๊ณผ์
n๋งํผ์ ์ซ์๋ค์ ๋ฐ์์ ๋ชจ๋ ๋ํ๊ณ ์ถ๋ ฅํด์ฃผ๋ฉด ๋๋ค.
code
function math() {
let [n, ...arr] = require("fs")
.readFileSync('/dev/stdin')
.toString()
.trim()
.split('\n')
.map(Number);
let sum = 0;
for (let i = 0; i < arr.length; i++) {
sum += arr[i];
}
console.log(sum);
};
math();
ํ๊ธฐ
'Algorithm > ๋ฌธ์ ํ์ด' ์นดํ ๊ณ ๋ฆฌ์ ๋ค๋ฅธ ๊ธ
[๋ฐฑ์ค] 5717๋ฒ - ์๊ทผ์ด์ ์น๊ตฌ๋ค (JS) (0) | 2023.08.03 |
---|---|
[๋ฐฑ์ค] 1373๋ฒ - 2์ง์ 8์ง์ (C++) (0) | 2023.08.02 |
[๋ฐฑ์ค] 28113๋ฒ - ์ ๋ณด์ฌ์ ๋์ค๊ตํต (JS) (0) | 2023.07.31 |
[๋ฐฑ์ค] 10815๋ฒ - ์ซ์ ์นด๋ (JS) (0) | 2023.07.30 |
[๋ฐฑ์ค] 2508๋ฒ - ์ฌํ ๋ฐ์ฌ ๊ณ ์ฐฝ์ (C++) (0) | 2023.07.28 |