3D라서 쉽지는 않았지만 간단한 시뮬레이션 문제였습니다.
풀면서 돌이켜보며 규칙이 있어야 한다고 했던 문제.
오늘 나는 코드로 범죄를 저질렀다. 야곰이 회개하라고 하더군요…
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)
![[Spring] 유효성 검증 [Spring] 유효성 검증](https://en.korea-industry.kr/wp-content/plugins/contextual-related-posts/default.png)