1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
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;
}
|