Advent of Code 2022 - 2nd attempt in c++
You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
|
|
|
#include <iostream>
|
|
|
|
#include <vector>
|
|
|
|
#include <algorithm>
|
|
|
|
|
|
|
|
using namespace std;
|
|
|
|
|
|
|
|
vector<unsigned> parse()
|
|
|
|
{
|
|
|
|
vector<unsigned> elves;
|
|
|
|
|
|
|
|
unsigned elf = 0;
|
|
|
|
for (string line; getline(cin, line);) {
|
|
|
|
if (line.empty()) {
|
|
|
|
elves.push_back(elf);
|
|
|
|
elf = 0;
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
elf += stoul(line);
|
|
|
|
}
|
|
|
|
|
|
|
|
sort(elves.begin(), elves.end(), greater<int>());
|
|
|
|
return elves;
|
|
|
|
}
|
|
|
|
|
|
|
|
unsigned p1(vector<unsigned> &input)
|
|
|
|
{
|
|
|
|
return input[0];
|
|
|
|
}
|
|
|
|
|
|
|
|
unsigned p2(vector<unsigned> &input)
|
|
|
|
{
|
|
|
|
return input[0] + input[1] + input[2];
|
|
|
|
}
|
|
|
|
|
|
|
|
int main()
|
|
|
|
{
|
|
|
|
auto input = parse();
|
|
|
|
cout << p1(input) << endl;
|
|
|
|
cout << p2(input) << endl;
|
|
|
|
}
|