parent
38cb42bfee
commit
68ce9ca703
2 changed files with 19 additions and 2 deletions
@ -1,9 +1,24 @@ |
||||
#include "Day01.h" |
||||
|
||||
Result Day01::Task1() { |
||||
return Day::Task1(); |
||||
subSums.push_back(0); |
||||
for (const std::string& line : input){ |
||||
if (line.empty()) |
||||
subSums.push_back(0); |
||||
else |
||||
subSums[subSums.size() - 1] += stoi(line); |
||||
} |
||||
return to_string(*std::max_element(subSums.begin(), subSums.end())); |
||||
} |
||||
|
||||
Result Day01::Task2() { |
||||
return Day::Task2(); |
||||
std::sort(subSums.begin(), subSums.end()); |
||||
|
||||
int sum = 0; |
||||
for (int i = 0; i < 3; i++){ |
||||
sum += subSums.back(); |
||||
subSums.pop_back(); |
||||
} |
||||
|
||||
return to_string(sum); |
||||
} |
Loading…
Reference in new issue