-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathProblem 8.cpp
More file actions
40 lines (33 loc) · 742 Bytes
/
Copy pathProblem 8.cpp
File metadata and controls
40 lines (33 loc) · 742 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
#include <iostream>
#include <fstream>
#include <vector>
#define NUMBERS_TO_CALCULATE 13
int main() {
std::ifstream input("input");
if(!input.good()) {
std::cerr << "Fehler beim oeffnen der Input-Datei\n";
return -1;
}
std::vector<char> numbers;
{
char c;
while(! input.eof()) {
input.get(c);
if(c != '\n') {
numbers.push_back(c);
}
}
}
std::size_t maxProduct = 0;
for(unsigned short i = 0; i < numbers.size() - NUMBERS_TO_CALCULATE; i++) {
std::size_t product = 1;
for(unsigned short pos = 0; pos < NUMBERS_TO_CALCULATE; pos++) {
product *= static_cast<char>(numbers[i + pos]) - '0';
}
if(product > maxProduct) {
maxProduct = product;
}
}
std::cout << maxProduct << '\n';
return 0;
}