Cleaned up day 1-3
This commit is contained in:
parent
c295529953
commit
ab21e8ad7d
6 changed files with 92 additions and 68 deletions
|
|
@ -1,19 +1,21 @@
|
|||
#include <iostream>
|
||||
#include <fstream>
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
const std::vector<std::string>& readToString(const std::string& path);
|
||||
|
||||
int main()
|
||||
{
|
||||
std::ifstream inputFile("../input/02.txt");
|
||||
std::string input;
|
||||
std::vector<std::string> commands = readToString("../input/02.txt");
|
||||
long h,d = 0;
|
||||
|
||||
while(std::getline(inputFile, input))
|
||||
for(auto& command : commands)
|
||||
{
|
||||
input.pop_back();
|
||||
int val = input.back() - 48;
|
||||
command.pop_back();
|
||||
int val = command.back() - 48;
|
||||
|
||||
switch(input.front())
|
||||
switch(command.front())
|
||||
{
|
||||
case 'f': h += val; break;
|
||||
case 'u': d -= val; break;
|
||||
|
|
@ -21,9 +23,19 @@ int main()
|
|||
}
|
||||
}
|
||||
|
||||
inputFile.close();
|
||||
|
||||
std::cout << d*h << std::endl;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
const std::vector<std::string>& readToString(const std::string& path)
|
||||
{
|
||||
std::ifstream inputFile(path);
|
||||
std::string input;
|
||||
static std::vector<std::string> inputs;
|
||||
|
||||
while(std::getline(inputFile, input))
|
||||
inputs.push_back(input);
|
||||
|
||||
return inputs;
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue