-
Notifications
You must be signed in to change notification settings - Fork 0
/
LargeSum.java
56 lines (46 loc) · 1.13 KB
/
LargeSum.java
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
51
52
53
54
55
56
import java.util.*;
import java.io.*;
public class LargeSum {
public static void main(String[] args) throws FileNotFoundException{
long st = System.nanoTime();
Scanner input = new Scanner(new File("C:/Users/Fernando/Downloads/EulerProject/LargeSum.txt"));
String[] sa = new String[100];
for (int k = 0; k<100; k++)
sa[k] = input.nextLine();
int[][] ia = new int[100][50];
for (int k = 0; k<100;k++){
for (int i = 0; i<50; i++){
ia[k][i] = sa[k].charAt(i)-48;
}
}
int[] answer = new int[55];
int danswer = 0;
for (int k = 49; k>=0; k--)
{
for (int i = 0; i<100; i++){
danswer += ia[i][k];
//System.out.println(danswer);
}
answer[k+3] += danswer%10;
danswer = (danswer/10);
answer[k+2] += danswer%10;
danswer = danswer/10;
answer[k+1] += danswer%10;
danswer = 0;
for (int j = 0; j<53;j++){
if(answer[j]>9)
{
answer[j-1] += answer[j]/10;
answer[j] = answer[j]%10;
j--;
}
}
}
for (int j = 1; j<53;j++){
System.out.print(answer[j]);
}
System.out.println();
long et = System.nanoTime();
System.out.println(et-st);
}
}