This commit is contained in:
Hugo Mårdbrink 2022-12-01 13:04:26 +01:00
parent ffcff856aa
commit 05becdbbbc
3 changed files with 2284 additions and 0 deletions

39
d1/main.cxx Normal file
View file

@ -0,0 +1,39 @@
#include <iostream>
#include <fstream>
#include <sstream>
#include <string>
#include <queue>
int main()
{
std::ifstream file{"../d1/input.txt"};
std::priority_queue<int> calories{};
std::uint32_t tot{0}, cur{0}, n;
std::string line;
while (std::getline(file, line))
{
std::stringstream iss(line);
if (line.length())
{
iss >> n;
cur += n;
}
else
{
calories.emplace(cur);
cur = 0;
}
}
tot = calories.top();
for (std::uint32_t i{0}; i < 2; i++)
{
calories.pop();
tot += calories.top();
}
std::cout << tot << std::endl;
return 0;
}