-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathProblem18.java
executable file
·55 lines (39 loc) · 1.13 KB
/
Problem18.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
import java.util.*;
import java.io.File;
import java.io.IOException;
public class helloworld {
public static void main(String []args)
throws IOException {
//System.out.println("Hello World");
Scanner s = new Scanner(new File("MaxPath.txt"));
MaxPath(s);
System.out.println("Answer: " + MaxPath(s));
}
public static int MaxPath(Scanner s) {
int[][] results = new int[15][15];
int rows = 0;
while (s.hasNextLine()) {
String line = s.nextLine();
String[] numbers = line.split("\\s+");
System.out.println(numbers.length);
for (int i = 0; i < numbers.length; i++) {
//System.out.println(numbers[i]);
results[rows][i] = Integer.parseInt(numbers[i]);
System.out.print(results[rows][i] + " ");
}
System.out.println(" ");
rows++;
}
System.out.println(rows);
rows--;
for (int row = 13; row >= 0; row--) {
for (int col = 0; col < rows; col++) {
results[row][col] += Math.max(results[row + 1][col], results[row + 1][col + 1]);
System.out.print(results[row][col] + " ");
}
System.out.println(" ");
rows--;
}
return results[0][0];
}
}