Added older advents
This commit is contained in:
parent
8db2505049
commit
9cf858b860
78 changed files with 13807 additions and 0 deletions
2250
advent_of_code_2022/day1/input.txt
Normal file
2250
advent_of_code_2022/day1/input.txt
Normal file
File diff suppressed because it is too large
Load diff
42
advent_of_code_2022/day1/main.cc
Normal file
42
advent_of_code_2022/day1/main.cc
Normal file
|
|
@ -0,0 +1,42 @@
|
|||
#include <algorithm>
|
||||
#include <charconv>
|
||||
#include <fmt/format.h>
|
||||
#include <iostream>
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
int main()
|
||||
{
|
||||
std::vector<std::int64_t> elves;
|
||||
elves.push_back(0);
|
||||
|
||||
std::int64_t calories{};
|
||||
std::string buffer;
|
||||
|
||||
while (!std::cin.eof())
|
||||
{
|
||||
std::getline(std::cin, buffer);
|
||||
|
||||
if (buffer.empty())
|
||||
{
|
||||
elves.push_back(0);
|
||||
continue;
|
||||
}
|
||||
|
||||
std::from_chars(buffer.data(), buffer.data() + buffer.size(), calories);
|
||||
elves.back() += calories;
|
||||
}
|
||||
|
||||
std::int64_t max = *std::max_element(elves.begin(), elves.end());
|
||||
fmt::print("Elf with most calories has {}\n", max);
|
||||
|
||||
std::int64_t top3{};
|
||||
for (std::size_t idx = 0; idx < 3; ++idx)
|
||||
{
|
||||
auto it = std::max_element(elves.begin(), elves.end());
|
||||
top3 += *it;
|
||||
*it = 0;
|
||||
}
|
||||
|
||||
fmt::print("Top3 elves with most calories have a combined: {}\n", top3);
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue