-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathindiana_level_1.cpp
124 lines (110 loc) · 2.57 KB
/
indiana_level_1.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
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
#include <iostream>
#include <string>
#include <sstream>
using namespace std;
#define TOP "TOP"
#define LEFT "LEFT"
#define RIGHT "RIGHT"
#define BOTTOM "BOTTOM"
#define ERROR "ERROR"
class Cell
{
public:
Cell(int t)
{
this->type = t;
}
int type;
string next_dir(string in);
};
string Cell::next_dir(string in)
{
switch(this->type)
{
case 0:
return ERROR;
case 1:
case 3:
return BOTTOM;
case 2:
case 6:
if(in == LEFT)
return RIGHT;
if(in == RIGHT)
return LEFT;
return ERROR;
case 4:
if(in == TOP)
return LEFT;
if(in == RIGHT)
return BOTTOM;
return ERROR;
case 5:
if(in == TOP)
return RIGHT;
if(in == LEFT)
return BOTTOM;
return ERROR;
case 7:
if((in == TOP) or (in == RIGHT))
return BOTTOM;
return ERROR;
case 8:
if((in == LEFT) or (in == RIGHT))
return BOTTOM;
return ERROR;
case 9:
if((in == LEFT) or (in == TOP))
return BOTTOM;
return ERROR;
case 10:
if(in == TOP)
return LEFT;
return ERROR;
case 11:
if(in == TOP)
return RIGHT;
return ERROR;
case 12:
if(in == RIGHT)
return BOTTOM;
return ERROR;
case 13:
if(in == LEFT)
return BOTTOM;
return ERROR;
default:
return ERROR;
}
}
int main()
{
// Read init information from standard input, if any
int w, h, ex;
cin >> w >> h;
int grid[20][20];
for(int y=0; y<h; y++)
for(int x=0; x<w; x++)
cin >> grid[x][y];
cin >> ex;
while (1) {
// Read information from standard input
int xi, yi;
string pos;
cin >> xi >> yi >> pos;
if(cin.fail()) break;
// Compute logic here
int type = grid[xi][yi];
Cell cell(type);
string out = cell.next_dir(pos);
if(out == LEFT)
xi--;
else if(out == RIGHT)
xi++;
else if(out == BOTTOM)
yi++;
// Write action to standard output
cout << xi << " " << yi << endl;
}
return 0;
}