[백준 5373] 큐빙 (삼성 기출)


문제

백준 삼성 SW 역량테스트 기출 문제

코드 GitHub

/****** BAEKJOON 5373  *****/
/***** SAMSUNG SW TEST *****/
/** Solved Date 2021-04-18 */

#include <iostream>
#include <vector>

using namespace std;

const char PORDER[6] = {'U', 'F', 'L', 'D', 'B', 'R'};
const int ROTATED[9] = {6, 3, 0, 7, 4, 1, 8, 5, 2};
const int SORDER[6][4][4] = {
    { {4, 6, 7, 8}, {2, 8, 5, 2}, {1, 2, 1, 0}, {5, 0, 3, 6} },
    { {0, 6, 7 ,8}, {2, 6, 7, 8}, {3, 6, 7, 8}, {5, 6, 7, 8} },
    { {4, 0, 3, 6}, {3, 8, 5, 2}, {1, 0, 3, 6}, {0, 0, 3, 6} },
    { {4, 2, 1, 0}, {5, 8, 5, 2}, {1, 6, 7, 8}, {2, 0, 3, 6} },
    { {3, 2, 1, 0}, {2, 2, 1, 0}, {0, 2, 1, 0}, {5, 2, 1, 0} },
    { {4, 8, 5, 2}, {0, 8, 5, 2}, {1, 8, 5, 2}, {3, 0, 3, 6} }
};

int RotateTop(char plane[9]) {
    char org[9];
    for(int i = 0; i < 9; i++) {
        org[i] = plane[i];
    }
    for(int i = 0; i < 9; i++) {
        plane[i] = org[ROTATED[i]];
    }
    return 1;
}
int RotateSide(char cube[][9], int pivot) {
    char tmp[3];
    for(int i = 0; i < 3; i++) {
        tmp[i] = cube[SORDER[pivot][0][0]][SORDER[pivot][0][i + 1]];
    }
    for(int i = 1; i < 4; i++) {
        for(int j = 0; j < 3; j++) {
            cube[SORDER[pivot][i - 1][0]][SORDER[pivot][i - 1][j + 1]] = cube[SORDER[pivot][i][0]][SORDER[pivot][i][j + 1]];
        }
    }
    for(int j = 0; j < 3; j++) {
        cube[SORDER[pivot][3][0]][SORDER[pivot][3][j + 1]] = tmp[j];
    }
    return 1;
}

int main() {
    int T;
    cin >> T;
    for(int t = 0; t < T; t++) {
        // U F L D B R
        char cube[6][9] = {
            {'w', 'w', 'w', 'w', 'w', 'w', 'w', 'w', 'w'},
            {'r', 'r', 'r', 'r', 'r', 'r', 'r', 'r', 'r'},
            {'g', 'g', 'g', 'g', 'g', 'g', 'g', 'g', 'g'},
            {'y', 'y', 'y', 'y', 'y', 'y', 'y', 'y', 'y'},
            {'o', 'o', 'o', 'o', 'o', 'o', 'o', 'o', 'o'},
            {'b', 'b', 'b', 'b', 'b', 'b', 'b', 'b', 'b'}
        };

        int N;
        cin >> N;

        for(int n = 0; n < N; n++) {
            char a, b;
            cin >> a >> b;

            int pln;
            bool clk;

            for(int i = 0; i < 6; i++) {
                if(PORDER[i] == a) {
                    pln = i;
                    break;
                }
            }

            clk = b == '+';

            RotateTop(cube[pln]);
            RotateSide(cube, pln);

            if(!clk) {
                RotateTop(cube[pln]);
                RotateSide(cube, pln);
                RotateTop(cube[pln]);
                RotateSide(cube, pln);
            }
        }

        for(int i = 0; i < 9; i++) {
            cout << cube[0][i];
            if(i % 3 == 2) {
                cout << '\n';
            }
        }
    }
}

Reference

댓글남기기