일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
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
- MySQL
- join
- 정규표현식
- 코플릿
- Algorithms
- 자바스크립트
- array
- 개발자_조이킴
- 개발자의 책장
- 재귀함수
- SQL
- 코딩테스트
- Hackerrank
- 프로그래머스
- 알고리즘
- 블록체인
- JavaScript
- select
- 역행자
- array.push()
- Developer_JoyKim
- for문
- Where
- node.js
- 최강의 인생
- 코딩공부
- Programmers
- 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
Solve Me First | HackerRank
This is an easy challenge to help you start coding in your favorite languages!
www.hackerrank.com
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