본문 바로가기

Problem/시뮬레이션

[C/C++] BOJ 1347 :: 미로 만들기

BOJ 1347 :: 미로 만들기



문제 링크 : https://www.acmicpc.net/problem/1347






나의 코드



Github : https://github.com/j2wooooo/Daliy_Algorithms/blob/master/Daliy_Algorithms/BOJ_1347/BOJ_1347.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
// 백준 알고리즘 1347번 :: 미로 만들기
#include<iostream>
#include<string>
using namespace std;
 
int N;
bool map[101][101];
// 남 서 북 동
int dx[4= {10-10};
int dy[4= {0-101};
 
int main()
{
    cin >> N;
 
    string str;
    cin >> str;
 
    int dir = 0;
    int cx = 50, cy = 50;
    int sx = cx, sy = cy, ex = cx, ey = cy;
 
    map[cx][cy] = true;;
 
    for (int j = 0; j < N; j++)
    {
        // 왼쪽으로 회전
        if (str[j] == 'L') dir = (dir + 3) % 4;
        // 오른쪽으로 회전
        else if (str[j] == 'R') dir = (dir + 1) % 4;
        // 앞으로 직진
        else if (str[j] == 'F')
        {
            cx += dx[dir];
            cy += dy[dir];
            map[cx][cy] = true;
            
            if (cx < sx) sx = cx;
            if (cy < sy) sy = cy;
            if (cx > ex) ex = cx;
            if (cy > ey) ey = cy;
        }
    }
 
    for (int i = sx; i <= ex; i++)
    {
        for (int j = sy; j <= ey; j++)
        {
            if(map[i][j]) cout << '.';
            else cout << '#';
        }
        cout << '\n';
    }
 
    return 0;
}
 
cs


'Problem > 시뮬레이션' 카테고리의 다른 글

[C/C++] BOJ 1986 :: 체스  (0) 2019.02.06
[C/C++] BOJ 1063 :: 킹  (0) 2019.01.23
[C/C++] BOJ 15685 :: 드래곤 커브  (0) 2019.01.21
[C/C++] BOJ 14890 :: 경사로  (0) 2019.01.11
[C/C++] BOJ 14499 :: 주사위 굴리기  (0) 2019.01.10