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.
AOC2022/01/solution.cpp

32 lines
689 B

#include <iostream>
#include <fstream>
#include <vector>
#include <bits/stdc++.h>
using namespace std;
int main()
{
string foodStr;
ifstream inputFile("input.txt");
vector<int> foodList;
int elfFood {0};
while ( getline(inputFile, foodStr))
{
if (foodStr == "")
{
foodList.push_back(elfFood);
elfFood = 0;
continue;
}
elfFood += stoi(foodStr);
}
sort(foodList.begin(), foodList.end());
int total {0};
for(int i {0}; i < 3; i++)
{
cout << foodList.back() << endl;
total += foodList.back();
foodList.pop_back();
}
cout << '\n' << total << endl;
}