1
0

Day 9 submission

This commit is contained in:
2021-12-09 01:11:44 -05:00
parent 533aae2f1c
commit dfcc3b4f76
15 changed files with 850 additions and 723 deletions
+36 -36
View File
@@ -1,36 +1,36 @@
#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;
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;
}
#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;
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;
}
+38 -38
View File
@@ -1,38 +1,38 @@
#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;
}
#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;
}