(三星)-丘氷(5373)



サムスン機能のテスト-実装

def clockwise(arr): # 원점에서 시계방향 90도 3번 = 반시계 90도 1번
    # 3 x 3 면의 정사각형 모서리
    tmp = arr[0][0]
    arr[0][0] = arr[2][0]
    arr[2][0] = arr[2][2]
    arr[2][2] = arr[0][2]
    arr[0][2] = tmp
    
    # 3 x 3 면의 마름모 모서리
    tmp = arr[0][1]
    arr[0][1] = arr[1][0]
    arr[1][0] = arr[2][1]
    arr[2][1] = arr[1][2]
    arr[1][2] = tmp
    
def U(c):
    if c == '+': # 시계방향
        k = 1 
    else: # 반시계 방향
        k = 3
    for _ in range(k): # 직접 큐브돌리기
        clockwise(cube[0]) # 윗면(U) 회전 로직
        # 윗면(U)가 회전함에 따라 좌, 우, 앞, 뒤 회전 로직
        # 우(id 4) = 뒤(id 5), 앞(id 1) = 우(id 4)
        # 좌(id 3) = 앞(id 1), 뒤(id 5) = 좌(id 3)
        tmp = cube[1][0][0], cube[1][0][1], cube[1][0][2]
        cube[1][0][0], cube[1][0][1], cube[1][0][2] = cube[4][2][0], cube[4][1][0], cube[4][0][0]
        cube[4][2][0], cube[4][1][0], cube[4][0][0] = cube[5][2][2], cube[5][2][1], cube[5][2][0]
        cube[5][2][2], cube[5][2][1], cube[5][2][0] = cube[3][0][2], cube[3][1][2], cube[3][2][2]
        cube[3][0][2], cube[3][1][2], cube[3][2][2] = tmp
 
def D(c):
    if c == '+':
        k = 1
    else:
        k = 3
    for _ in range(k):
        clockwise(cube[2])
        tmp = cube[4][0][2], cube[4][1][2], cube[4][2][2]
        cube[4][0][2], cube[4][1][2], cube[4][2][2] = cube[1][2][2], cube[1][2][1], cube[1][2][0]
        cube[1][2][2], cube[1][2][1], cube[1][2][0] = cube[3][2][0], cube[3][1][0], cube[3][0][0]
        cube[3][2][0], cube[3][1][0], cube[3][0][0] = cube[5][0][0], cube[5][0][1], cube[5][0][2]
        cube[5][0][0], cube[5][0][1], cube[5][0][2] = tmp
 
def R(c):
    if c == '+':
        k = 1
    else:
        k = 3
    for _ in range(k):
        clockwise(cube[4])
        tmp = cube[0][0][2], cube[0][1][2], cube[0][2][2]
        cube[0][0][2], cube[0][1][2], cube[0][2][2] = cube[1][0][2], cube[1][1][2], cube[1][2][2]
        cube[1][0][2], cube[1][1][2], cube[1][2][2] = cube[2][0][2], cube[2][1][2], cube[2][2][2]
        cube[2][0][2], cube[2][1][2], cube[2][2][2] = cube[5][0][2], cube[5][1][2], cube[5][2][2]
        cube[5][0][2], cube[5][1][2], cube[5][2][2] = tmp
 
def L(c):
    if c == '+':
        k = 1
    else:
        k = 3
    for _ in range(k):
        clockwise(cube[3])
        tmp = cube[0][0][0], cube[0][1][0], cube[0][2][0]
        cube[0][0][0], cube[0][1][0], cube[0][2][0] = cube[5][0][0], cube[5][1][0], cube[5][2][0]
        cube[5][0][0], cube[5][1][0], cube[5][2][0] = cube[2][0][0], cube[2][1][0], cube[2][2][0]
        cube[2][0][0], cube[2][1][0], cube[2][2][0] = cube[1][0][0], cube[1][1][0], cube[1][2][0]
        cube[1][0][0], cube[1][1][0], cube[1][2][0] = tmp
 
def F(c):
    if c == '+':
        k = 1
    else:
        k = 3
    for _ in range(k):
        clockwise(cube[1])
        tmp = cube[0][2][0], cube[0][2][1], cube[0][2][2]
        cube[0][2][0], cube[0][2][1], cube[0][2][2] = cube[3][2][0], cube[3][2][1], cube[3][2][2]
        cube[3][2][0], cube[3][2][1], cube[3][2][2] = cube[2][0][2], cube[2][0][1], cube[2][0][0]
        cube[2][0][2], cube[2][0][1], cube[2][0][0] = cube[4][2][0], cube[4][2][1], cube[4][2][2]
        cube[4][2][0], cube[4][2][1], cube[4][2][2] = tmp
 
def B(c):
    if c == '+':
        k = 1
    else:
        k = 3
    for _ in range(k):
        clockwise(cube[5])
        tmp = cube[0][0][0], cube[0][0][1], cube[0][0][2]
        cube[0][0][0], cube[0][0][1], cube[0][0][2] = cube[4][0][0], cube[4][0][1], cube[4][0][2]
        cube[4][0][0], cube[4][0][1], cube[4][0][2] = cube[2][2][2], cube[2][2][1], cube[2][2][0]
        cube[2][2][2], cube[2][2][1], cube[2][2][0] = cube[3][0][0], cube[3][0][1], cube[3][0][2]
        cube[3][0][0], cube[3][0][1], cube[3][0][2] = tmp

from copy import deepcopy
CUBE = [[[] for _ in range(3)] for _ in range(6)]
s = 'wrygbo' # U,F,D,L,R,B

for i in range(6): # 3 x 3 면이 6개인 정육면체 큐브
    for j in range(3):
        for _ in range(3):
            CUBE[i][j].append(s[i])
            
for i in range(int(input())):
    n = int(input())
    cmd = input().split()
    cube = deepcopy(CUBE)
    
    while cmd:
        c = cmd.pop(0)
        if c[0] == 'L': # 기준면과 (+, -) 방향 케이스 구분
            L(c[1])
        elif c[0] == 'D':
            D(c[1])
        elif c[0] == 'B':
            B(c[1])
        elif c[0] == 'R':
            R(c[1])
        elif c[0] == 'U':
            U(c[1])
        elif c[0] == 'F':
            F(c[1])
            
    for j in range(3):
        print(''.join(cube[0][j]))
    
参照)
https://br-brg.tistory.com/26