-
Notifications
You must be signed in to change notification settings - Fork 0
/
poj1835-astronaut.c
69 lines (61 loc) · 963 Bytes
/
poj1835-astronaut.c
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
68
69
#include <stdio.h>
#include <string.h>
int reverse[6] = {3, 4, 5, 0, 1, 2};
int t, n;
int x, y, z;
int p, h, l;
char cmd[100];
int s;
int
main()
{
int i, temp;
scanf("%d", &t);
while (t--)
{
scanf("%d", &n);
x = y = z = 0;
p = 0; h = 2; l = 4;
for (i = 0; i < n; i++)
{
scanf("%s %d", cmd, &s);
if (strcmp(cmd, "back") == 0)
{
p = reverse[p];
l = reverse[l];
}
if (strcmp(cmd, "left") == 0)
{
temp = p;
p = l;
l = reverse[temp];
}
if (strcmp(cmd, "right") == 0)
{
temp = p;
p = reverse[l];
l = temp;
}
if (strcmp(cmd, "up") == 0)
{
temp = p;
p = h;
h = reverse[temp];
}
if (strcmp(cmd, "down") == 0)
{
temp = p;
p = reverse[h];
h = temp;
}
if (p == 0) x += s;
if (p == 1) y += s;
if (p == 2) z += s;
if (p == 3) x -= s;
if (p == 4) y -= s;
if (p == 5) z -= s;
}
printf("%d %d %d %d\n", x, y, z, p);
}
return 0;
}