-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathProblem67.cs
More file actions
35 lines (30 loc) · 1017 Bytes
/
Problem67.cs
File metadata and controls
35 lines (30 loc) · 1017 Bytes
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
using System;
using System.IO;
class Problem67
{
static void Main(string[] args)
{
// read in the triangle data from file and parse in to jagged array structure
string[] lines = System.IO.File.ReadAllLines("problem67_data.txt");
int[][] triangle = new int[lines.Length][];
for (int i = 0; i < lines.Length; i++)
{
string[] values = lines[i].Split(' ');
triangle[i] = new int[values.Length];
for (int j = 0; j < values.Length; j++)
{
triangle[i][j] = int.Parse(values[j]);
}
}
// Starting from the bottom of the tree move up adding sequentially
for (int i = triangle.Length - 1; i > 0; i--)
{
for (int j = 0; j < triangle[i].Length - 1; j++)
{
triangle[i - 1][j] += Math.Max(triangle[i][j], triangle[i][j + 1]);
}
}
Console.WriteLine(triangle[0][0]);
Console.ReadLine();
}
}