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.

43 lines
675 B

2 years ago
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
2 years ago
typedef vector<unsigned> Input;
Input parse()
2 years ago
{
2 years ago
Input elves;
2 years ago
unsigned elf = 0;
2 years ago
for (string line; getline(cin, line);) {
2 years ago
if (line.empty()) {
elves.push_back(elf);
elf = 0;
continue;
}
elf += stoul(line);
}
2 years ago
sort(elves.begin(), elves.end(), greater<unsigned>());
2 years ago
return elves;
}
2 years ago
unsigned p1(Input &input)
2 years ago
{
return input[0];
}
2 years ago
unsigned p2(Input &input)
2 years ago
{
return input[0] + input[1] + input[2];
}
int main()
{
auto input = parse();
cout << p1(input) << endl;
cout << p2(input) << endl;
}