일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
1 | 2 | 3 | 4 | |||
5 | 6 | 7 | 8 | 9 | 10 | 11 |
12 | 13 | 14 | 15 | 16 | 17 | 18 |
19 | 20 | 21 | 22 | 23 | 24 | 25 |
26 | 27 | 28 | 29 | 30 | 31 |
Tags
- 알고리즘
- 정규표현식
- 자바스크립트
- Developer_JoyKim
- 역행자
- Where
- array
- 재귀함수
- select
- 프로그래머스
- 코딩테스트
- 개발자_조이킴
- SQL
- 코딩공부
- 블록체인
- array.push()
- MySQL
- for문
- 코플릿
- 코드스테이츠
- 배열
- node.js
- 개발자의 책장
- JavaScript
- join
- Hackerrank
- Programmers
- Algorithms
- array.slice()
- 최강의 인생
Archives
- Today
- Total
CodingSpace
[HackerRank/Algorithms] Warmup - A Very Big Sum 본문
Problem. Warmup - A Very Big Sum
Link.
https://www.hackerrank.com/challenges/a-very-big-sum/problem?isFullScreen=true
Description.
In this challenge, you are required to calculate and print the sum of the elements in an array,
keeping in mind that some of those integers may be quite large.
Key Point.
My Answer.
'use strict';
const fs = require('fs');
process.stdin.resume();
process.stdin.setEncoding('utf-8');
let inputString = '';
let currentLine = 0;
process.stdin.on('data', function(inputStdin) {
inputString += inputStdin;
});
process.stdin.on('end', function() {
inputString = inputString.split('\n');
main();
});
function readLine() {
return inputString[currentLine++];
}
/*
* Complete the 'aVeryBigSum' function below.
*
* The function is expected to return a LONG_INTEGER.
* The function accepts LONG_INTEGER_ARRAY ar as parameter.
*/
function aVeryBigSum(ar) {
// Write your code here
let sum = 0;
for(let i = 0; i < ar.length; i++) {
sum = sum + ar[i];
}
return sum;
}
function main() {
const ws = fs.createWriteStream(process.env.OUTPUT_PATH);
const arCount = parseInt(readLine().trim(), 10);
const ar = readLine().replace(/\s+$/g, '').split(' ').map(arTemp => parseInt(arTemp, 10));
const result = aVeryBigSum(ar);
ws.write(result + '\n');
ws.end();
}
References.
'HackerRank > Algorithm' 카테고리의 다른 글
[HackerRank/Algorithms] Warmup - Birthday Cake Candles (0) | 2022.08.22 |
---|---|
[HackerRank/Algorithms] Warmup - Mini-Max Sum (0) | 2022.08.22 |
[HackerRank/Algorithms] Warmup - Plus Minus (0) | 2022.08.21 |
[HackerRank/Algorithms] Warmup - Diagonal Difference (0) | 2022.08.21 |
[HackerRank/Algorithms] Warmup - Solve Me First (0) | 2022.08.18 |
Comments