diff options
author | Leah Neukirchen <leah@vuxu.org> | 2017-12-12 13:33:29 +0100 |
---|---|---|
committer | Leah Neukirchen <leah@vuxu.org> | 2017-12-12 13:33:29 +0100 |
commit | 7ebb9a12f811f9b334815276621a2bdef391e917 (patch) | |
tree | fc1e01e7fc9cc1584264437f315301aed93d6abf /day11.cc | |
parent | bc3f64835aca551f54cf2b2df86200d991b97a07 (diff) | |
download | adventofcode2017-7ebb9a12f811f9b334815276621a2bdef391e917.tar.gz adventofcode2017-7ebb9a12f811f9b334815276621a2bdef391e917.tar.xz adventofcode2017-7ebb9a12f811f9b334815276621a2bdef391e917.zip |
day11
Diffstat (limited to 'day11.cc')
-rw-r--r-- | day11.cc | 28 |
1 files changed, 28 insertions, 0 deletions
diff --git a/day11.cc b/day11.cc new file mode 100644 index 0000000..9c51591 --- /dev/null +++ b/day11.cc @@ -0,0 +1,28 @@ +#include <algorithm> +#include <iostream> +#include <sstream> +#include <string> +#include <vector> + +using namespace std; + +int +main() { + string sym; + int x{0}, y{0}, d{0}, maxd{0}; + + while (getline(cin, sym, ',')) { + if (cin.eof()) sym.pop_back(); + + if (sym == "n" ) x--; + else if (sym == "s" ) x++; + else if (sym == "se") y++; + else if (sym == "nw") y--; + else if (sym == "ne") x--, y++; + else if (sym == "sw") x++, y--; + + maxd = max(maxd, d = max({x,-x,y,-y,x+y,-x-y})); + } + + cout << d << endl << maxd << endl; +} |