1
0
Fork 0
Advent2021/Day 2/Marcus/cpp/part2.cpp

39 lines
793 B
C++
Raw Normal View History

2021-12-09 06:11:44 +00:00
#include <iostream>
#include <stdlib.h>
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;
}