-
Notifications
You must be signed in to change notification settings - Fork 0
/
day1_1.cpp
46 lines (33 loc) · 1.05 KB
/
day1_1.cpp
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
#include <iostream>
#include <fstream>
#include <vector>
std::vector<std::string> readFile(const std::string& fileName) {
std::vector<std::string> fileData;
std::string currentLine;
std::ifstream input(fileName);
while(getline(input, currentLine)) {
fileData.push_back(currentLine);
}
return fileData;
}
std::vector<int> storeIndividual(const std::vector<std::string>& fileData) {
std::vector<int> individual;
int currentCount = 0;
for(auto& element : fileData) {
if(element.empty()) {
individual.push_back(currentCount);
currentCount = 0;
}
else {
currentCount += stoi(element);
}
}
return individual;
}
int main() {
std::vector<std::string> fileData = readFile("day1_input.txt");
std::vector<int> individual = storeIndividual(fileData);
int greatest = *std::max_element(individual.begin(), individual.end());
std::cout << "The greatest amount amount being carried is \"" << greatest << "\" calories.\n";
return 0;
}