-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path1374_미로만들기.cpp
57 lines (50 loc) · 1005 Bytes
/
1374_미로만들기.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
#include <iostream>
#include <string>
using namespace std;
bool arr[101][101];
int dx[4] = {1, 0, -1, 0};
int dy[4] = {0, -1, 0, 1};
int main()
{
string str;
int len;
cin >> len;
cin >> str;
int sx = 50, sy = 50;
arr[sx][sy] = true;
int dir = 0;
int l = 50, r = 50, u = 50, d = 50;
for (int i = 0; i < len; i++)
{
char c = str[i];
if (c == 'R')
{
dir = (dir + 1) % 4;
}
else if (c == 'L')
{
dir = (dir + 3) % 4;
}
else
{
sx += dx[dir];
sy += dy[dir];
arr[sx][sy] = true;
l = min(l, sy);
u = min(u, sx);
d = max(d, sx);
r = max(r, sy);
}
}
for (int i = u; i <= d; i++)
{
for (int j = l; j <= r; j++)
{
if (arr[i][j])
cout << '.';
else
cout << '#';
}
cout << endl;
}
}