1
0
Fork 0
This commit is contained in:
Marcus Penate 2022-12-01 00:59:58 -05:00
parent 25fb122377
commit 95db0b1fa8
4 changed files with 55 additions and 8 deletions

2
.gitignore vendored Normal file
View File

@ -0,0 +1,2 @@
*/**
!*/*.cpp

25
Day1/part1.cpp Normal file
View File

@ -0,0 +1,25 @@
#include <iostream>
#include <string>
int main(int argc, char* argv[])
{
std::string line;
int total = 0;
int max = 0;
while(std::getline(std::cin, line))
{
if (0 == line.size())
{
if (total > max)
{
max = total;
}
total = 0;
}
else
{
total += stoi(line);
}
}
std::cout << max << std::endl;
}

26
Day1/part2.cpp Normal file
View File

@ -0,0 +1,26 @@
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
int main(int argc, char* argv[])
{
std::string line;
int total = 0;
std::vector<int> sums;
while(std::getline(std::cin, line))
{
if (0 == line.size())
{
sums.push_back(total);
total = 0;
}
else
{
total += stoi(line);
}
}
std::sort(sums.begin(), sums.end(), std::greater<>());
std::cout << sums[0] + sums[1] + sums[2] << std::endl;
}

View File

@ -2,12 +2,6 @@
Advent of Code for 2022 Advent of Code for 2022
## How to contribute # Branch format
To contribute to the Advent of Code 2022, please pull master and create a branch with your name. Uploading code files at partX.cpp in each days folder. Compile the part with `g++ partX.cpp -o partX`. Download your input file as `inptuX` and run the program with `./partX < inputX`.
Recommended folder structure is `{Day}\{Language}\{Part}`
## Tips
It is recommended to include small document on how the program works and how to compile & run the program.