-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathProblem3.cpp
More file actions
43 lines (33 loc) · 1.22 KB
/
Problem3.cpp
File metadata and controls
43 lines (33 loc) · 1.22 KB
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
#include "Problem3.h"
///////////////////////////////////////////
// Logic
//////////////////////////////////////////
void Problem3::ExecuteTests()
{
int arr[]= { 1, 2 , 8, 100};
vector<int> moneyInEachHouse(arr, arr + sizeof(arr) / sizeof(arr[0]));
cout << "input : ";
for (int i(0); i < moneyInEachHouse.size(); i++){ cout << moneyInEachHouse[i] << " ";}
cout << endl;
if (moneyInEachHouse.size() < 2)
{
cout << "too small an input" << endl;
return ;
}
//base case
int maxMoneyTillNMinusTwoHouse(moneyInEachHouse[0]);
int maxMoneyTillNMinusOneHouse(max(moneyInEachHouse[0], moneyInEachHouse[1]));
for (int i(2); i < moneyInEachHouse.size(); i++) {
int val = max(maxMoneyTillNMinusOneHouse,
moneyInEachHouse[i] + maxMoneyTillNMinusTwoHouse);
maxMoneyTillNMinusTwoHouse = maxMoneyTillNMinusOneHouse;
maxMoneyTillNMinusOneHouse = val;
}
cout << "output is" << maxMoneyTillNMinusOneHouse << endl;
}
void Problem3::DescribeProblem()
{
cout << endl;
cout << "---------------------------------------------------" << endl;
cout << "-------------------PROBLEM 3-----------------------" << endl;
}