Day 1
This commit is contained in:
parent
ffcff856aa
commit
05becdbbbc
3 changed files with 2284 additions and 0 deletions
|
|
@ -9,3 +9,4 @@ if( NOT CMAKE_BUILD_TYPE )
|
|||
SET( CMAKE_BUILD_TYPE Release )
|
||||
endif()
|
||||
|
||||
add_executable(d1 "d1/main.cxx")
|
||||
|
|
|
|||
2244
d1/input.txt
Normal file
2244
d1/input.txt
Normal file
File diff suppressed because it is too large
Load diff
39
d1/main.cxx
Normal file
39
d1/main.cxx
Normal 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;
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue