-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path1347.cpp
More file actions
51 lines (46 loc) · 1.53 KB
/
1347.cpp
File metadata and controls
51 lines (46 loc) · 1.53 KB
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
#include <iostream>
#include <algorithm>
#include <vector>
using namespace std;
int main() {
ios::sync_with_stdio(false);
cin.tie(NULL);
int len;
string s;
vector<pair<int, int> > dir;
vector<int> dir_count(4, 50);
int now_dir = 0;
pair<int, int> cur_pos = make_pair(50, 50);
vector<vector<int> > map(101, vector<int>(101, 0));
dir.push_back(make_pair(1, 0));
dir.push_back(make_pair(0, -1));
dir.push_back(make_pair(-1, 0));
dir.push_back(make_pair(0, 1));
cin >> len;
cin >> s;
map[cur_pos.first][cur_pos.second] = 1;
for (char c : s) {
if (c == 'R') now_dir = (now_dir + 1) % 4;
else if (c == 'L') {
if (now_dir == 0) now_dir = 3;
else now_dir -= 1;
}
else {
cur_pos.first += dir[now_dir].first;
cur_pos.second += dir[now_dir].second;
if (now_dir == 0) dir_count[now_dir] = max(dir_count[now_dir], cur_pos.first);
else if (now_dir == 1) dir_count[now_dir] = min(dir_count[now_dir], cur_pos.second);
else if (now_dir == 2) dir_count[now_dir] = min(dir_count[now_dir], cur_pos.first);
else dir_count[now_dir] = max(dir_count[now_dir], cur_pos.second);
map[cur_pos.first][cur_pos.second] = 1;
}
}
for (int i = dir_count[2]; i <= dir_count[0]; i++) {
for (int j = dir_count[1]; j <= dir_count[3]; j++) {
if (map[i][j] == 0) cout << "#";
else cout << ".";
}
cout << "\n";
}
return 0;
}