-
Notifications
You must be signed in to change notification settings - Fork 7
Expand file tree
/
Copy pathq18.cpp
More file actions
51 lines (29 loc) · 648 Bytes
/
q18.cpp
File metadata and controls
51 lines (29 loc) · 648 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
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
#include<bits/stdc++.h>
#include <fstream>
#include <string>
using namespace std;
int main()
{
string myText;
ifstream MyReadFile("pyramid.txt");
int i = 0;
int j = 0;
int num[15][15];
while (getline (MyReadFile, myText))
{
for ( int i = 0 ; i < myText.length(); i+=3)
{
num[j][i/3] = 10*((myText[i] - 48)) + (myText[i+1] - 48) ;
}
j++;
}
for(int n = 14;n >= 1;n--)
{
int j = n;
for(int l = 0; l < j; l++)
{
num[n-1][l] += max(num[n][l] , num[n][l+1]);
}
}
cout<<num[0][0];
}