From e5c50e03318a3f490ae645641445284216848848 Mon Sep 17 00:00:00 2001 From: Marcus Penate Date: Thu, 2 Dec 2021 00:19:51 -0500 Subject: [PATCH] Day 2 submission --- Day 2/Marcus/cpp/part1.cpp | 36 ++++++++++++++++++++++++++++++++++++ Day 2/Marcus/cpp/part2.cpp | 38 ++++++++++++++++++++++++++++++++++++++ 2 files changed, 74 insertions(+) create mode 100644 Day 2/Marcus/cpp/part1.cpp create mode 100644 Day 2/Marcus/cpp/part2.cpp diff --git a/Day 2/Marcus/cpp/part1.cpp b/Day 2/Marcus/cpp/part1.cpp new file mode 100644 index 0000000..a61ce02 --- /dev/null +++ b/Day 2/Marcus/cpp/part1.cpp @@ -0,0 +1,36 @@ +#include +#include + +using namespace std; + +int main() +{ + string input; + const string forward = "forward"; + const string up = "up"; + const string down = "down"; + int horizontal = 0; + int depth = 0; + + while(getline(cin,input)) + { + int amount = atoi(&input.c_str()[input.find(' ')]);; + + if (string::npos != input.find(forward)) + { + horizontal += amount; + } + else if (string::npos != input.find(up)) + { + depth -= amount; + } + else if (string::npos != input.find(down)) + { + depth += amount; + } + } + + cout << horizontal*depth << endl; + + return 0; +} diff --git a/Day 2/Marcus/cpp/part2.cpp b/Day 2/Marcus/cpp/part2.cpp new file mode 100644 index 0000000..c66f973 --- /dev/null +++ b/Day 2/Marcus/cpp/part2.cpp @@ -0,0 +1,38 @@ +#include +#include + +using namespace std; + +int main() +{ + string input; + const string forward = "forward"; + const string up = "up"; + const string down = "down"; + int horizontal = 0; + int depth = 0; + int aim = 0; + + while(getline(cin,input)) + { + int amount = atoi(&input.c_str()[input.find(' ')]);; + + if (string::npos != input.find(forward)) + { + horizontal += amount; + depth += amount*aim; + } + else if (string::npos != input.find(up)) + { + aim -= amount; + } + else if (string::npos != input.find(down)) + { + aim += amount; + } + } + + cout << horizontal*depth << endl; + + return 0; +}