Hackerrank – Problem description
The problem description – Hackerrank.
Solution
We need to sum all given numbers. The catch is to use a feature of chosen programming language, which allows us operation with big numbers (e. g. BigInteger
in Java)
I created solution in:
All solutions are also available on my GitHub profile.
Java
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 |
import java.math.BigInteger; import java.util.Scanner; public class LargeSum { public static void main(String[] args) { Scanner scanner = new Scanner(System.in); int numbers = Integer.parseInt(scanner.nextLine()); BigInteger sum = BigInteger.ZERO; for (int i = 0; i < numbers; i++) { String input = scanner.nextLine(); sum = sum.add(new BigInteger(input)); } System.out.println(sum.toString().substring(0, 10)); scanner.close(); } } |