본문 바로가기

코테

5373 큐빙 - Python

728x90
반응형
SMALL

3차원이라서 쉽지않았지만 단순 시뮬레이션 문제였다.

푸는 내내 분명 규칙이 있을텐데, 하며 돌아봤던 문제.

오늘도 코드로 범죄를 저질렀음. 야곰님께서 그랬다 회개하면된다고...

 

https://www.acmicpc.net/problem/5373

 

5373번: 큐빙

각 테스트 케이스에 대해서 큐브를 모두 돌린 후의 윗 면의 색상을 출력한다. 첫 번째 줄에는 뒷 면과 접하는 칸의 색을 출력하고, 두 번째, 세 번째 줄은 순서대로 출력하면 된다. 흰색은 w, 노란

www.acmicpc.net

import copy

w,y,r,o,g,b = "w", "y", "r", "o", "g", "b"

tmp = ["","",""]
answer = []
front = [[r,r,r],
         [r,r,r],
         [r,r,r]]
back = [[o,o,o],
        [o,o,o],
        [o,o,o]]
up = [[w,w,w],
      [w,w,w],
      [w,w,w]]
right = [[b,b,b],
         [b,b,b],
         [b,b,b]]
down = [[y,y,y],
        [y,y,y],
        [y,y,y]]
left = [[g,g,g],
        [g,g,g],
        [g,g,g]]

def transFaceLeft(graph):
    tmpPeice = graph[0][0]
    graph[0][0] = graph[0][2]
    graph[0][2] = graph[2][2]
    graph[2][2] = graph[2][0]
    graph[2][0] = tmpPeice
    tmpPeice = graph[0][1]
    graph[0][1] = graph[1][2]
    graph[1][2] = graph[2][1]
    graph[2][1] = graph[1][0]
    graph[1][0] = tmpPeice
    return graph
def transFaceRight(graph):
    tmpPeice = graph[0][0]
    graph[0][0] = graph[2][0]
    graph[2][0] = graph[2][2]
    graph[2][2] = graph[0][2]
    graph[0][2] = tmpPeice
    tmpPeice = graph[0][1]
    graph[0][1] = graph[1][0]
    graph[1][0] = graph[2][1]
    graph[2][1] = graph[1][2]
    graph[1][2] = tmpPeice
    return graph

def trans(way, direction, qube):
    global answer
    tmp, front, back, up, down, right, left = qube[0], qube[1], qube[2], qube[3], qube[4], qube[5], qube[6]
    if way == "L" and direction == "-":
        tmp[0], tmp[1], tmp[2] = up[0][0], up[1][0], up[2][0]
        up[0][0], up[1][0], up[2][0] = front[0][0], front[1][0], front[2][0]
        front[0][0], front[1][0], front[2][0] = down[2][2], down[1][2], down[0][2]
        down[2][2], down[1][2], down[0][2] = back[2][2], back[1][2], back[0][2]
        back[2][2], back[1][2], back[0][2] = tmp[0], tmp[1], tmp[2]
        left = transFaceLeft(left)

    if way == "L" and direction == "+":
        tmp[0], tmp[1], tmp[2] = up[0][0], up[1][0], up[2][0]
        up[0][0], up[1][0], up[2][0] = back[2][2], back[1][2], back[0][2]
        back[2][2], back[1][2], back[0][2] = down[2][2], down[1][2], down[0][2]
        down[2][2], down[1][2], down[0][2] = front[0][0], front[1][0], front[2][0]
        front[0][0], front[1][0], front[2][0] = tmp[0], tmp[1], tmp[2]
        left = transFaceRight(left)

    if way == "R" and direction == "-":
        tmp[0], tmp[1], tmp[2] = up[0][2], up[1][2], up[2][2]
        up[0][2], up[1][2], up[2][2] = back[2][0], back[1][0], back[0][0]
        back[2][0], back[1][0], back[0][0] = down[2][0], down[1][0], down[0][0]
        down[2][0], down[1][0], down[0][0] = front[0][2], front[1][2], front[2][2]
        front[0][2], front[1][2], front[2][2] = tmp[0], tmp[1], tmp[2]
        right = transFaceLeft(right)

    if way == "R" and direction == "+":
        tmp[0], tmp[1], tmp[2] = up[0][2], up[1][2], up[2][2]
        up[0][2], up[1][2], up[2][2] = front[0][2], front[1][2], front[2][2]
        front[0][2], front[1][2], front[2][2] = down[2][0], down[1][0], down[0][0] #헷갈림
        down[2][0], down[1][0], down[0][0] = back[2][0], back[1][0], back[0][0]
        back[2][0], back[1][0], back[0][0] = tmp[0], tmp[1], tmp[2]
        right = transFaceRight(right)

    if way == "F" and direction == "-":
        tmp[0], tmp[1], tmp[2] = up[2][0], up[2][1], up[2][2]
        up[2][0], up[2][1], up[2][2] = right[0][0], right[1][0], right[2][0]
        right[0][0], right[1][0], right[2][0] = down[2][0], down[2][1], down[2][2]
        down[2][0], down[2][1], down[2][2] = left[2][2], left[1][2], left[0][2]
        left[2][2], left[1][2], left[0][2] = tmp[0], tmp[1], tmp[2]
        front = transFaceLeft(front)

    if way == "F" and direction == "+":
        tmp[0], tmp[1], tmp[2] = up[2][0],up[2][1],up[2][2]
        up[2][0], up[2][1], up[2][2] = left[2][2], left[1][2], left[0][2]
        left[2][2], left[1][2], left[0][2] = down[2][0], down[2][1], down[2][2]
        down[2][0], down[2][1], down[2][2] = right[0][0], right[1][0], right[2][0]
        right[0][0], right[1][0], right[2][0] = tmp[0], tmp[1], tmp[2]
        front = transFaceRight(front)

    if way == "B" and direction == "-":
        tmp[0], tmp[1], tmp[2] = up[0][0], up[0][1], up[0][2]
        up[0][0], up[0][1], up[0][2] = left[2][0], left[1][0], left[0][0]
        left[2][0], left[1][0], left[0][0] = down[0][0], down[0][1], down[0][2]
        down[0][0], down[0][1], down[0][2] = right[0][2], right[1][2], right[2][2]
        right[0][2], right[1][2], right[2][2] = tmp[0], tmp[1], tmp[2]
        back = transFaceLeft(back)

    if way == "B" and direction == "+":
        tmp[0], tmp[1], tmp[2] = up[0][0], up[0][1], up[0][2]
        up[0][0], up[0][1], up[0][2] = right[0][2], right[1][2], right[2][2]
        right[0][2], right[1][2], right[2][2] = down[0][0], down[0][1], down[0][2]
        down[0][0], down[0][1], down[0][2] = left[2][0], left[1][0], left[0][0]
        left[2][0], left[1][0], left[0][0] = tmp[0], tmp[1], tmp[2]
        back = transFaceRight(back)

    if way == "U" and direction == "-":
        tmp[0], tmp[1], tmp[2] = front[0][0], front[0][1], front[0][2]
        front[0][0], front[0][1], front[0][2] = left[0][0], left[0][1], left[0][2]
        left[0][0], left[0][1], left[0][2] = back[0][0], back[0][1], back[0][2]
        back[0][0], back[0][1], back[0][2] = right[0][0], right[0][1], right[0][2]
        right[0][0], right[0][1], right[0][2] = tmp[0], tmp[1], tmp[2]
        up = transFaceLeft(up)

    if way == "U" and direction == "+":
        tmp[0], tmp[1], tmp[2] = front[0][0], front[0][1], front[0][2]
        front[0][0], front[0][1], front[0][2] = right[0][0], right[0][1], right[0][2]
        right[0][0], right[0][1], right[0][2] = back[0][0], back[0][1], back[0][2]
        back[0][0], back[0][1], back[0][2] = left[0][0], left[0][1], left[0][2]
        left[0][0], left[0][1], left[0][2] = tmp[0], tmp[1], tmp[2]
        up = transFaceRight(up)

    if way == "D" and direction == "-":
        tmp[0], tmp[1], tmp[2] = front[2][0], front[2][1], front[2][2]
        front[2][0], front[2][1], front[2][2] = right[2][0], right[2][1], right[2][2]
        right[2][0], right[2][1], right[2][2] = back[2][0], back[2][1], back[2][2]
        back[2][0], back[2][1], back[2][2] = left[2][0], left[2][1], left[2][2]
        left[2][0], left[2][1], left[2][2] = tmp[0], tmp[1], tmp[2]
        down = transFaceLeft(down)

    if way == "D" and direction == "+":
        tmp[0], tmp[1], tmp[2] = front[2][0], front[2][1], front[2][2]
        front[2][0], front[2][1], front[2][2] = left[2][0], left[2][1], left[2][2]
        left[2][0], left[2][1], left[2][2] = back[2][0], back[2][1], back[2][2]
        back[2][0], back[2][1], back[2][2] = right[2][0], right[2][1], right[2][2]
        right[2][0], right[2][1], right[2][2] = tmp[0], tmp[1], tmp[2]
        down = transFaceRight(down)

def excute(n, qube):
    count = input().split()
    wayDirections = input().split()
    for wayDirection in wayDirections:
        way = wayDirection[0]
        direction = wayDirection[1]
        trans(way, direction, qube)
    for i in qube[3]:
        answer.append("".join(i))

n = int(input())
qube = [tmp, front, back, up, down, right, left]
for count in range(n):
    tmpQube = copy.deepcopy(qube)
    excute(count, tmpQube)

for cubeside in answer:
    print(cubeside)

 

728x90
반응형
LIST

'코테' 카테고리의 다른 글

산타의 선물 공장2  (0) 2023.03.24
코드트리 빵  (0) 2023.03.24
14503 로봇 청소기 python  (0) 2023.03.23
14499 - 주사위 굴리기  (0) 2023.03.22
2048 (Easy)  (0) 2023.03.21