ABOUT ME

-

Today
-
Yesterday
-
Total
-
  • 백준_킹_1063
    Algorithm 2018. 9. 5. 21:26



    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
    58
    59
    60
    61
    62
    63
    64
    65
    66
    67
    68
    69
    70
    71
    72
    73
    74
    75
    76
    77
    78
    79
    80
    81
    82
    83
    84
    85
    86
    87
    88
    89
    90
    91
    92
    93
    94
    95
    96
    97
    98
    99
    100
    101
    102
    103
    104
    105
    106
    107
    108
    109
    110
    111
    112
    113
    114
    115
    116
    117
    118
    119
    120
    121
    122
    123
    124
    125
    126
    127
    128
    129
    130
    131
    132
    133
    134
    135
    136
    137
    138
    139
    140
    141
    142
    143
    144
    145
    146
    147
    148
    149
    150
    151
    152
    153
    154
    155
    156
    157
    158
    159
    160
    161
    162
    163
    164
    165
    166
    167
    168
    169
    170
    171
    172
    173
    174
    175
    176
    177
    178
    179
    180
    181
    182
    #include <iostream>
    #include <string>
    using namespace std;
     
    int stoneLocation[2];
    int kingLocation[2];
     
    bool overlap() {
        if ((kingLocation[0== stoneLocation[0]) && (kingLocation[1== stoneLocation[1])) {
            return true;
        }
        return false;
    }
    // king location and stone location are overlapped
    bool except() {
        if (kingLocation[0> 8 || kingLocation[0< 1 || kingLocation[1]>8 || kingLocation[1< 1) {
            return true;
        }
        if (stoneLocation[0> 8 || stoneLocation[0< 1 || stoneLocation[1]>8 || stoneLocation[1< 1) {
            return true;
        }
        return false;
    }
    // king location or stone location are escape
     
    void moveFun(string command) {
        if (command == "R") {
            kingLocation[0]++;
            if (overlap()) {
                stoneLocation[0]++;
                if (except()) {
                    kingLocation[0]--;
                    stoneLocation[0]--;
                }
                return;
            }
            if (except()) {
                kingLocation[0]--;
            }
        }
        else if (command == "L") {
            kingLocation[0]--;
            if (overlap()) {
                stoneLocation[0]--;
                if (except()) {
                    kingLocation[0]++;
                    stoneLocation[0]++;
                }
                return;
            }
            if (except()) {
                kingLocation[0]++;
            }
        }
        else if (command == "B") {
            kingLocation[1]--;
            if (overlap()) {
                stoneLocation[1]--;
                if (except()) {
                    kingLocation[1]++;
                    stoneLocation[1]++;
                }
                return;
            }
            if (except()) {
                kingLocation[1]++;
            }
        }
        else if (command == "T") {
            kingLocation[1]++;
            if (overlap()) {
                stoneLocation[1]++;
                if (except()) {
                    kingLocation[1]--;
                    stoneLocation[1]--;
                }
                return;
            }
            if (except()) {
                kingLocation[1]--;
            }
        }
        else if (command == "RT") {
            kingLocation[0]++;
            kingLocation[1]++;
            if (overlap()) {
                stoneLocation[0]++;
                stoneLocation[1]++;
                if (except()) {
                    kingLocation[0]--;
                    kingLocation[1]--;
                    stoneLocation[0]--;
                    stoneLocation[1]--;
                }
                return;
            }
            if (except()) {
                kingLocation[0]--;
                kingLocation[1]--;
            }
        }
        else if (command == "LT") {
            kingLocation[0]--;
            kingLocation[1]++;
            if (overlap()) {
                stoneLocation[0]--;
                stoneLocation[1]++;
                if (except()) {
                    kingLocation[0]++;
                    kingLocation[1]--;
                    stoneLocation[0]++;
                    stoneLocation[1]--;
                }
                return;
            }
            if (except()) {
                kingLocation[0]++;
                kingLocation[1]--;
            }
        }
        else if (command == "RB") {
            kingLocation[0]++;
            kingLocation[1]--;
            if (overlap()) {
                stoneLocation[0]++;
                stoneLocation[1]--;
                if (except()) {
                    kingLocation[0]--;
                    kingLocation[1]++;
                    stoneLocation[0]--;
                    stoneLocation[1]++;
                }
                return;
            }
            if (except()) {
                kingLocation[0]--;
                kingLocation[1]++;
            }
        }
        else if (command == "LB") {
            kingLocation[0]--;
            kingLocation[1]--;
            if (overlap()) {
                stoneLocation[0]--;
                stoneLocation[1]--;
                if (except()) {
                    kingLocation[0]++;
                    kingLocation[1]++;
                    stoneLocation[0]++;
                    stoneLocation[1]++;
                }
                return;
            }
            if (except()) {
                kingLocation[0]++;
                kingLocation[1]++;
            }
        }
        else {
            return;
        }
    }
     
    int main() {
        string stoneStart, kingStart;
        string command;
        int count;
        cin >> kingStart >> stoneStart >> count;
        kingLocation[0= kingStart[0- 64;
        kingLocation[1= kingStart[1- 48;
        stoneLocation[0= stoneStart[0- 64;
        stoneLocation[1= stoneStart[1- 48;
        //Initialize
     
        for (int i = 0; i < count; i++) {
            cin >> command;
            moveFun(command);
        }
     
        cout << char(kingLocation[0+ 64<< kingLocation[1<< endl;
        cout << char(stoneLocation[0+ 64<< stoneLocation[1<< endl;
    }
    cs


    'Algorithm' 카테고리의 다른 글

    그래프_백준_반복수열_2331  (0) 2018.09.04
    그래프_백준_순열 사이클_10451  (0) 2018.08.31
    그래프_백준_이분 그래프_1707  (0) 2018.08.31
    그래프_백준_연결 요소_11724  (0) 2018.08.30
    그래프_백준_DFS와 BFS_1260  (0) 2018.08.30
Designed by Tistory.