diff --git a/src/main/scala/algorithms/aVeryBigSum/Solution.scala b/src/main/scala/algorithms/aVeryBigSum/Solution.scala new file mode 100644 index 0000000..621f12a --- /dev/null +++ b/src/main/scala/algorithms/aVeryBigSum/Solution.scala @@ -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 + +} \ No newline at end of file diff --git a/src/main/scala/algorithms/aVeryBigSum/SolutionBest.scala b/src/main/scala/algorithms/aVeryBigSum/SolutionBest.scala new file mode 100644 index 0000000..cc8751f --- /dev/null +++ b/src/main/scala/algorithms/aVeryBigSum/SolutionBest.scala @@ -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) + } +} \ No newline at end of file