-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path067.cpp
More file actions
35 lines (26 loc) · 759 Bytes
/
067.cpp
File metadata and controls
35 lines (26 loc) · 759 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
#include <stdio.h>
#include <vector>
#include <algorithm>
#include <fstream>
#include <sstream>
int maximum_path(std::vector<std::vector<int>> triangle)
{
for (int y = triangle.size() - 2; y >= 0; y--)
for (int x = 0; x < triangle[y].size(); x++)
triangle[y][x] += std::max(triangle[y + 1][x], triangle[y + 1][x + 1]);
return triangle[0][0];
}
int main(int argc, char** argv)
{
std::vector<std::vector<int>> triangle;
std::ifstream file("data/p067_triangle.txt");
std::string line, num;
while (std::getline(file, line)) {
std::istringstream iss(line);
triangle.push_back({});
while (getline(iss, num, ' '))
triangle.back().push_back(std::stoi(num));
}
printf("%i\n", maximum_path(triangle));
return 0;
}