-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathA_Very_Big_sum.ts
50 lines (35 loc) · 1.11 KB
/
A_Very_Big_sum.ts
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
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
'use strict';
import { WriteStream, createWriteStream } from "fs";
process.stdin.resume();
process.stdin.setEncoding('utf-8');
let inputString: string = '';
let inputLines: string[] = [];
let currentLine: number = 0;
process.stdin.on('data', function(inputStdin: string): void {
inputString += inputStdin;
});
process.stdin.on('end', function(): void {
inputLines = inputString.split('\n');
inputString = '';
main();
});
function readLine(): string {
return inputLines[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: number[]): number {
return ar.reduce( (a:number,b:number) => a+b,0);
}
function main() {
const ws: WriteStream = createWriteStream(process.env['OUTPUT_PATH']);
const arCount: number = parseInt(readLine().trim(), 10);
const ar: number[] = readLine().replace(/\s+$/g, '').split(' ').map(arTemp => parseInt(arTemp, 10));
const result: number = aVeryBigSum(ar);
ws.write(result + '\n');
ws.end();
}