File tree 1 file changed +46
-0
lines changed
1 file changed +46
-0
lines changed Original file line number Diff line number Diff line change
1
+ #include < iostream>
2
+ #include < fstream>
3
+
4
+ using namespace std ;
5
+
6
+ const int windowSize = 3 ;
7
+ int window[windowSize];
8
+
9
+ void shiftWindow (int newValue) {
10
+ window[0 ] = window[1 ];
11
+ window[1 ] = window[2 ];
12
+ window[2 ] = newValue;
13
+ }
14
+
15
+ int windowTotal () {
16
+ int ret = 0 ;
17
+ for (int i = 0 ; i < windowSize; i++) ret += window[i];
18
+ return ret;
19
+ }
20
+
21
+ int main () {
22
+ ifstream inFile (" ../input" );
23
+ int inputNumbers[2000 ];
24
+
25
+ int curInNumber;
26
+ int curInLineInx = -1 ;
27
+ while (inFile >> curInNumber) {
28
+ curInLineInx += 1 ;
29
+ inputNumbers[curInLineInx] = curInNumber;
30
+ }
31
+
32
+ // Set the first window
33
+ for (int i = 0 ; i <= windowSize; i++) window[i] = inputNumbers[i];
34
+
35
+ int wentDeeperTimes = 0 ;
36
+ for (int i = 3 ; i < 2000 ; i++) {
37
+ int prev = windowTotal ();
38
+ shiftWindow (inputNumbers[i]);
39
+ int cur = windowTotal ();
40
+ if (cur > prev) wentDeeperTimes += 1 ;
41
+ }
42
+
43
+ cout << wentDeeperTimes << endl;
44
+ }
45
+
46
+
You can’t perform that action at this time.
0 commit comments