#include <vector>
#include <queue>
#include <iostream>
#include <cmath>
#include <algorithm>
#include <deque>
#include <numeric>
#include <map>
#define ll long long
using namespace std;
char board[110][110];
int dc[4] = {0, -1, 0, 1};
int dr[4] = {1, 0, -1, 0};
int min_r=50;
int max_r=50;
int min_c=50;
int max_c=50;
int dir = 0;
int N;
void right()
{
dir++;
if(dir>3) dir-=4;
}
void left()
{
dir--;
if(dir<0) dir+=4;
}
void updateRange(int r, int c)
{
min_r = min(min_r, r);
max_r = max(max_r, r);
min_c = min(min_c, c);
max_c = max(max_c, c);
}
int main() {
ios::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
cin >> N;
for(int i=0;i<110;i++)
fill(board[i], board[i]+110, '#');
int r = 50;
int c = 50;
board[r][c] = '.';
for(int i=0;i<N;i++)
{
char ch;
cin >> ch;
if(ch == 'R') right();
else if(ch == 'L') left();
else if(ch == 'F'){
int nr = r + dr[dir];
int nc = c + dc[dir];
board[nr][nc] = '.';
r=nr; c=nc;
updateRange(r, c);
}
}
for(int a=min_r; a<=max_r;a++)
{
for(int b=min_c; b<=max_c;b++)
cout << board[a][b];
cout << '\n';
}
return 0;
}
- 핵심
min_r / max_r / min_c / max_c
를 통해서 범위 관리
board판을 넉넉
하게 잡은 뒤 50부터 인덱스 시작