-
Notifications
You must be signed in to change notification settings - Fork 0
/
id0018.c
56 lines (46 loc) · 1.04 KB
/
id0018.c
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
// Licensed under the MIT License.
// Maximum Path Sum I
// Maximum Path Sum II
#include "../lib/euler.h"
#define BUFFER_SIZE 512
#define MAX_HEIGHT 100
int main(int argc, String argv[])
{
int id;
if (argc == 2)
{
id = strtol(argv[1], NULL, 10);
}
else
{
id = 18;
}
int m = 0;
int items[MAX_HEIGHT][MAX_HEIGHT + 1] = { 0 };
char buffer[BUFFER_SIZE];
clock_t start = clock();
while (fgets(buffer, sizeof buffer, stdin))
{
String substring = buffer;
for (int j = 0; j < m + 1; j++)
{
items[m][j] = strtol(substring, &substring, 10);
}
m++;
}
for (int i = m - 2; i >= 0; i--)
{
for (int j = 0; j < i + 1; j++)
{
if (items[i + 1][j] > items[i + 1][j + 1])
{
items[i][j] += items[i + 1][j];
}
else
{
items[i][j] += items[i + 1][j + 1];
}
}
}
return euler_submit(id, items[0][0], start);
}