-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathaoc1711_hex_grid.cpp
67 lines (60 loc) · 2.01 KB
/
aoc1711_hex_grid.cpp
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
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
/* ************************************************************************** */
/* */
/* \\ /`/`` */
/* ~\o o_ 0 0\ */
/* / \__) (u ); _ _ */
/* / \/ \/ / \ \/ \/ \ */
/* /( . . ) ( )\ */
/* / \_____/ \_______/ \ */
/* [] [] [[] [[] *. */
/* []] []] [[] [[] */
/* */
/* ****************************************************************** nuo *** */
#include "iostream"
#include "sstream"
using namespace std;
int man(int x, int y);
int main()
{
string step, s;
char c;
int max, end, x, y;
max = x = y = 0;
cin >> s;
stringstream ss(s);
while (getline(ss, step, ','))
{
if (step == "n")
y += 2;
if (step == "s")
y -= 2;
if (step == "ne")
{
x += 1;
y += 1;
}
if (step == "se")
{
x += 1;
y -= 1;
}
if (step == "sw")
{
x -= 1;
y -= 1;
}
if (step == "nw")
{
x -= 1;
y += 1;
}
end = man(x, y);
max = max < end ? end : max;
}
cout << "Star 1 : " << end << endl;
cout << "Star 2 : " << max << endl;
}
int man(int x, int y)
{
return ((abs(x) + abs(y)) / 2);
}