-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathccc02s3.cpp
79 lines (73 loc) · 1.57 KB
/
ccc02s3.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
#include <bits/stdc++.h>
using namespace std;
vector<char> mv;
vector<vector<char>> arr;
int r, c, m;
bool valid(int x, int y)
{
if (x < 0 || y < 0 || x >= r || y >= c)
return false;
return arr[x][y] != 'X';
}
void run(int x, int y, int dir)
{
if (!valid(x, y))
return;
for (auto &mm : mv)
{
switch (mm)
{
case 'L':
dir++;
break;
case 'R':
dir--;
break;
case 'F':
switch (dir)
{
case 0:
x++;
break;
case 1:
y++;
break;
case 2:
x--;
break;
case 3:
y--;
break;
}
break;
}
dir %= 4;
dir += 4;
dir %= 4;
if (!valid(x, y))
return;
}
arr[x][y] = '*';
}
int main()
{
scanf("%i%i", &r, &c);
arr.resize(r, vector<char>(c));
for (auto &x : arr)
for (auto &y : x)
scanf(" %c", &y);
scanf("%i", &m);
mv.resize(m);
for (auto &x : mv)
scanf(" %c", &x);
for (int x = 0; x < r; x++)
for (int y = 0; y < c; y++)
for (int dir = 0; dir < 4; dir++)
run(x, y, dir);
for (auto &x : arr)
{
for (auto &y : x)
printf("%c", y);
printf("\n");
}
}