Solves a very big sum

This commit is contained in:
julien Lengrand-Lambert
2017-03-27 00:01:22 +02:00
parent fcd19cd0a8
commit fd084600a3
2 changed files with 35 additions and 0 deletions

View File

@@ -0,0 +1,22 @@
package algorithms
/**
* Created by jll on 3/26/2017.
*/
object Solution {
def main(args: Array[String]) {
val sc = new java.util.Scanner (System.in);
var n = sc.nextInt();
var arr = new Array[Int](n);
for(arr_i <- 0 to n-1) {
arr(arr_i) = sc.nextInt();
}
print(sum(arr))
}
def sum(arr: Array[Int]) : Long =
arr.map(x => x.toLong).sum
}

View File

@@ -0,0 +1,13 @@
package algorithms.aVeryBigSum
/**
* Created by jll on 3/26/2017.
* From https://codepair.hackerrank.com/paper/PqyQ4XMD?b=eyJyb2xlIjoiY2FuZGlkYXRlIiwibmFtZSI6IkFpcmJhbGxtYW4iLCJlbWFpbCI6ImpsZW5ncmFuZEBnbWFpbC5jb20ifQ%3D%3D
*/
object Solution {
def main(args: Array[String]) {
val line = io.Source.stdin.getLines().drop(1)
println(line.next().split(" ").map(_.toLong).sum)
}
}