#include <stdio.h> #include <iostream> #include <algorithm> #include <string> using namespace std; int N; string command; char map[110][110]; int dir = 2; // 북(0) 동(1) 남(2) 서(3) void execute(int &x, int &y, char command) { if(command == 'R') { dir = (dir+1) % 4; } else if(command == 'L') { dir = (dir+3) % 4; } else if(command == 'F') { if(dir == 0) { x -= 1; } else if(dir == 1) { y += 1; } else if(dir == 2) { x += 1; } else if(dir == 3) { y -= 1; } map[x][y] = '.'; } } int main(void) { // freopen("B1062_input.txt", "r", stdin); cin >> N >> command; for(int i = 0; i < 110; i++) { for(int j = 0; j < 110; j++) { map[i][j] = '#'; } } // 초기값 55, 55를 잡으면 맵의 크기가 110이기때문에 상하좌우 한 방향으로 50칸을 가더라도 범위안에서 해결 가능 int x = 55; int y = 55; map[x][y] = '.'; for(int i = 0; i < N; i++) { execute(x, y, command[i]); } // 미로의 왼쪽위, 오른쪽아래 양끝점 구하기 int leftX = 55, leftY = 55, rightX = 55, rightY = 55; for(int i = 0; i < 110; i++) { for(int j = 0; j < 110; j++) { if(map[i][j] == '.') { if(leftX > i) { leftX = i; } if(leftY > j) { leftY = j; } if(rightX < i) { rightX = i; } if(rightY < j) { rightY = j; } } } } for(int i = leftX; i <= rightX; i++) { for(int j = leftY; j <= rightY; j++) { cout << map[i][j]; } cout << endl; } return 0; } | cs |
'Baekjoon > Simulation' 카테고리의 다른 글
[백준 2980] 도로와 신호등 (Simulation) (C/C++) (★★) (0) | 2020.03.25 |
---|---|
[백준 2164] 카드 2 (Simulation) (C/C++) (0) | 2020.03.25 |
[백준 1986] 체스 (Simulation) (C/C++) (★) (0) | 2020.03.25 |
[백준 1063] 킹 (Simulation) (C/C++) (0) | 2020.03.24 |
[백준 1547] 공 (Simulation) (C/C++) (0) | 2020.03.24 |