Problem:


  MathJax.Hub.Config({ tex2jax: { inlineMath: [["$","$"], ["\\(","\\)"]], processEscapes: true }});

Dice I

  Write a program to simulate rolling a dice, which can be constructed by the following net.

  As shown in the figures, each face is identified by a different label from 1 to 6.

  Write a program which reads integers assigned to each face identified by the label and a sequence of commands to roll the dice, and prints the integer on the top face. At the initial state, the dice is located as shown in the above figures.

Input

  In the first line, six integers assigned to faces are given in ascending order of their corresponding labels.

  In the second line, a string which represents a sequence of commands, is given. The command is one of 'E', 'N', 'S' and 'W' representing four directions shown in the above figures.

Output

  Print the integer which appears on the top face after the simulation.

Constraints

$0 \leq $ the integer assigned to a face $ \leq 100$

$0 \leq $ the length of the command $\leq 100$

Sample Input 1

1 2 4 8 16 32
SE

Sample Output 1

8

You are given a dice where 1, 2, 4, 8, 16 are 32 are assigned to a face labeled by 1, 2, ..., 6 respectively. After you roll the dice to the direction S and then to the direction E, you can see 8 on the top face.

Sample Input 2

1 2 4 8 16 32
EESWN

Sample Output 2

32



Sample input:
1 2 4 8 16 32
SE


Sample output:
8

Submission status: Accepted

Solution code:
dice = input().split()
cmd = input()
for i in range(len(cmd)):
    if cmd[i] == 'E':
        dice[0], dice[3], dice[5], dice[2] = dice[3], dice[5], dice[2], dice[0]
    elif cmd[i] == 'W':
        dice[0], dice[2], dice[5], dice[3] = dice[2], dice[5], dice[3], dice[0]
    elif cmd[i] == 'S':
        dice[0], dice[4], dice[5], dice[1] = dice[4], dice[5], dice[1], dice[0]
    elif cmd[i] == 'N':
        dice[0], dice[1], dice[5], dice[4] = dice[1], dice[5], dice[4], dice[0]

print(dice[0])

Submission status: Accepted

Solution code:
class Dice():
    def __init__(self):
        self.face = [i for i in range(6)]
        self.memo = [i for i in range(6)]

    def setface(self,initface):
        for i in range(6):
            self.face[i] = initface[i]

    def roll(self,direction):
        for i in range(6):
            self.memo[i] = self.face[i]
        index = {'E':(3,1,0,5,4,2),'N':(1,5,2,3,0,4),'S':(4,0,2,3,5,1),'W':(2,1,5,0,4,3)}
        for i in range(6):
            self.face[i] = self.memo[index[direction][i]]

    def top(self):
        return self.face[0]

dice = Dice()
initface = list(map(int,input().split()))
dice.setface(initface)
route = input()
for direction in route:
    dice.roll(direction)
print(dice.top())

Submission status: Accepted

Solution code:
class Dice():
	def __init__(self,li):
		self.directionList = li
		self.top   = 1
		self.south = 2
		self.east  = 3
		self.west  = 4
		self.norse = 5
		self.low   = 6

	def get_top(self):
		return self.directionList[self.top-1]

	def advance_dice(self,direction):
		if direction == "E":
			tmp = self.top
			self.top = self.west
			self.west = self.low
			self.low = self.east
			self.east = tmp
		elif direction == "S":
			tmp = self.top
			self.top = self.norse
			self.norse = self.low
			self.low = self.south
			self.south = tmp
		elif direction == "W":
			self.advance_dice("E")
			self.advance_dice("E")
			self.advance_dice("E")
		elif direction == "N":
			self.advance_dice("S")
			self.advance_dice("S")
			self.advance_dice("S")

if __name__ == '__main__':
	li = list(map(int,input().split()))
	direction = list(input())
	dice  = Dice(li=li)
	for i in range(len(direction)):
		dice.advance_dice(direction[i])

	print(dice.get_top())

Submission status: Accepted

Solution code:
class Dise():
    def __init__(self, d1,d2,d3,d4,d5,d6):
        self.s1 = d1
        self.s2 = d2
        self.s3 = d3
        self.s4 = d4
        self.s5 = d5
        self.s6 = d6

    def roll_N(self):
        sub = self.s1
        self.s1 = self.s2
        self.s2 = self.s6
        self.s6 = self.s5
        self.s5 = sub

    def roll_S(self):
        sub = self.s1
        self.s1 = self.s5
        self.s5 = self.s6
        self.s6 = self.s2
        self.s2 = sub

    def roll_E(self):
        sub = self.s1
        self.s1 = self.s4
        self.s4 = self.s6
        self.s6 = self.s3
        self.s3 = sub

    def roll_W(self):
        sub = self.s1
        self.s1 = self.s3
        self.s3 = self.s6
        self.s6 = self.s4
        self.s4 = sub

    def top(self):
        print(self.s1)



inline = input().split()
d1, d2, d3, d4, d5, d6 = (int(xi) for xi in inline)
roll1 = input()
dise1 = Dise(d1, d2, d3, d4, d5, d6)

length = len(roll1)
for xi in range(length):
    if roll1[xi]=="N":
        dise1.roll_N()
    if roll1[xi]=="E":
        dise1.roll_E()
    if roll1[xi]=="W":
        dise1.roll_W()
    if roll1[xi]=="S":
        dise1.roll_S()

dise1.top()

Submission status: Accepted

Solution code:
class dice:
    def __init__(self, f):
        assert(len(f) == 6)
        self.face = f
        self.N = [1, 5, 2, 3, 0, 4]
        self.S = [4, 0, 2, 3, 5, 1]
        self.E = [3, 1, 0, 5, 4, 2]
        self.W = [2, 1, 5, 0, 4, 3]

    def rotate(self, dir):
        rot = self.__getattribute__(dir)
        old = self.face
        new = [-1 for _ in range(6)]
        for i in range(6):
            new[i] = old[rot[i]]
        self.face = new

d = list(map(int, input().split()))
D = dice(d)
Q = input()
for c in Q:
    D.rotate(c)
print(D.face[0])

Submission status: Accepted

Solution code:
class Dice(object):
    def __init__(self, listnum):
        self.a = listnum[0]
        self.b = listnum[1]
        self.c = listnum[2]
        self.d = listnum[3]
        self.e = listnum[4]
        self.f = listnum[5]

    def moveS(self):
        listnew =[]
        listnew.append(self.e)
        listnew.append(self.a)
        listnew.append(self.c)
        listnew.append(self.d)
        listnew.append(self.f)
        listnew.append(self.b)
        return Dice(listnew)

    def moveN(self):
        listnew =[]
        listnew.append(self.b)
        listnew.append(self.f)
        listnew.append(self.c)
        listnew.append(self.d)
        listnew.append(self.a)
        listnew.append(self.e)
        return Dice(listnew)

    def moveE(self):
        listnew =[]
        listnew.append(self.d)
        listnew.append(self.b)
        listnew.append(self.a)
        listnew.append(self.f)
        listnew.append(self.e)
        listnew.append(self.c)
        return Dice(listnew)

    def moveW(self):
        listnew =[]
        listnew.append(self.c)
        listnew.append(self.b)
        listnew.append(self.f)
        listnew.append(self.a)
        listnew.append(self.e)
        listnew.append(self.d)
        return Dice(listnew)


No1 = Dice(input().split())
listmove = list(input())
for i in range(len(listmove)):
    if listmove[i] == "S":
        No1 = No1.moveS()
    elif listmove[i] == "N":
        No1 = No1.moveN()
    elif listmove[i] == "E":
        No1 = No1.moveE()
    elif listmove[i] == "W":
        No1 = No1.moveW()

print(No1.a)

Submission status: Accepted

Solution code:
class Dice():

    def __init__(self, d):
        self.d = d
        self.north = [2, 6, 3, 4, 1, 5]
        self.south = [5, 1, 3, 4, 6, 2]
        self.east = [4, 2, 1, 6, 5, 3]
        self.west = [3, 2, 6, 1, 5, 4]

    def roll(self, direction):
        if direction == 'S':
            self.d = [ self.d[self.south[i]-1] for i in range(6) ]
        elif direction == 'N':
            self.d = [ self.d[self.north[i]-1] for i in range(6) ]
        elif direction == 'E':
            self.d = [ self.d[self.east[i]-1] for i in range(6) ]
        elif direction == 'W':
            self.d = [ self.d[self.west[i]-1] for i in range(6) ]

    def getDice(self):
        return self.d


s = [ int(s) for s in input().split() ]
command = input().strip()

dice = Dice(s)
for c in command:
    dice.roll(c)

r = dice.getDice()
print(r[0])

Submission status: Accepted

Solution code:
dice = list(map(int, input().split()))

s = str(input())
n = len(s)

dicel = [[0 for i in range(6)] for j in range(n+1)]

for i in range(6):
  dicel[0][i] = dice[i]

for j in range(n):
  if s[j] == "N":
    dicel[j+1][0] = dicel[j][1]
    dicel[j+1][1] = dicel[j][5]
    dicel[j+1][5] = dicel[j][4]
    dicel[j+1][4] = dicel[j][0]
    dicel[j+1][2] = dicel[j][2]
    dicel[j+1][3] = dicel[j][3]
  elif s[j] == "E":
    dicel[j+1][0] = dicel[j][3]
    dicel[j+1][3] = dicel[j][5]
    dicel[j+1][5] = dicel[j][2]
    dicel[j+1][2] = dicel[j][0]
    dicel[j+1][1] = dicel[j][1]
    dicel[j+1][4] = dicel[j][4]
  elif s[j] == "S":
    dicel[j+1][0] = dicel[j][4]
    dicel[j+1][4] = dicel[j][5]
    dicel[j+1][5] = dicel[j][1]
    dicel[j+1][1] = dicel[j][0]
    dicel[j+1][2] = dicel[j][2]
    dicel[j+1][3] = dicel[j][3]
  else:
    dicel[j+1][0] = dicel[j][2]
    dicel[j+1][2] = dicel[j][5]
    dicel[j+1][5] = dicel[j][3]
    dicel[j+1][3] = dicel[j][0]
    dicel[j+1][1] = dicel[j][1]
    dicel[j+1][4] = dicel[j][4]

print(dicel[n][0])

Submission status: Accepted

Solution code:
import sys
#立方体で数字が自由なさいころ
class Dice:
    def __init__(self,top,bottom,front,rear,right,left):
        self.top=top
        self.front=front
        self.right=right
        self.bottom=bottom
        self.rear=rear
        self.left=left

    def rotate_front(self):
        t,b,f,r=self.top,self.bottom,self.front,self.rear
        self.top=r
        self.bottom=f
        self.front=t
        self.rear=b

    def rotate_rear(self):
        t,b,f,r=self.top,self.bottom,self.front,self.rear
        self.top=f
        self.bottom=r
        self.front=b
        self.rear=t

    def rotate_right(self):
        t,b,r,l=self.top,self.bottom,self.right,self.left
        self.top=l
        self.bottom=r
        self.right=t
        self.left=b

    def rotate_left(self):
        t,b,r,l=self.top,self.bottom,self.right,self.left
        self.top=r
        self.bottom=l
        self.right=b
        self.left=t

sys.setrecursionlimit(10 ** 6)
int1 = lambda x: int(x) - 1
p2D = lambda x: print(*x, sep="\n")

def main():
    top,front,right,left,rear,bottom=map(int, input().split())
    d=Dice(top,bottom,front,rear,right,left)
    s=input()
    for c in s:
        if c=="N":d.rotate_rear()
        if c=="S":d.rotate_front()
        if c=="E":d.rotate_right()
        if c=="W":d.rotate_left()
    print(d.top)

main()

Submission status: Accepted

Solution code:
n = list(map(int,input().split()))
j = list(input())

for i in range(len(j)):
    if j[i] == 'E':
        n[0], n[3], n[5], n[2] = n[3], n[5], n[2], n[0]

    elif j[i] == 'W':
        n[0], n[2], n[5], n[3] = n[2], n[5], n[3], n[0]

    elif j[i] == 'S':
        n[0], n[4], n[5], n[1] = n[4], n[5], n[1], n[0]

    else:
        n[0], n[1], n[5], n[4]  = n[1], n[5], n[4], n[0]

print(n[0])

Submission status: Accepted

Solution code:
class Dice():
    def __init__(self, arr):
        self.top = arr[0]
        self.front = arr[1]
        self.right = arr[2]
        self.left = arr[3]
        self.back = arr[4]
        self.bottom = arr[5]
        
    def rotate(self, direction):
        if direction == "N":
            self.back, self.top, self.front, self.bottom = \
            self.top, self.front, self.bottom, self.back
        elif direction == "S":
            self.front, self.bottom, self.back, self.top = \
            self.top, self.front, self.bottom, self.back
        elif direction == "E":
            self.right, self.bottom, self.left, self.top = \
            self.top, self.right, self.bottom, self.left
        elif direction == "W":
            self.left, self.bottom, self.right, self.top = \
            self.top, self.left, self.bottom, self.right
        
            
dice = Dice(input().split())

direction_list = list(input())

for direction in direction_list:
    dice.rotate(direction)

print(dice.top)

Submission status: Accepted

Solution code:
num=list(map(int,input().split()))
s=input()
for i in s:
    if i=='E':
        num=[num[3],num[1],num[0],num[5],num[4],num[2]]    
    if i=='W':
        num=[num[2],num[1],num[5],num[0],num[4],num[3]]
    if i=='S':
        num=[num[4],num[0],num[2],num[3],num[5],num[1]]
    if i=='N':
        num=[num[1],num[5],num[2],num[3],num[0],num[4]]
        
print(num[0])

Submission status: Accepted

Solution code:
arr=input().split()
x=input()
for i in x:
    if i=='W':
        arr=[arr[k-1] for k in [3,2,6,1,5,4]]
    if i=='E':
        arr=[arr[k-1] for k in [4,2,1,6,5,3]]
    if i=='N':
        arr=[arr[k-1] for k in [2,6,3,4,1,5]]
    if i=='S':
        arr=[arr[k-1] for k in [5,1,3,4,6,2]]
print(arr[0])

Submission status: Accepted

Solution code:
class Dice:
    def __init__(self, U, S, E, W, N, D):
        self.u, self.d = U, D
        self.e, self.w = E, W
        self.s, self.n = S, N
    
    def roll(self, commmand):
        if command == 'E':
            self.e, self.u, self.w, self.d = self.u, self.w, self.d, self.e
        elif command == 'W':
            self.e, self.u, self.w, self.d = self.d, self.e, self.u, self.w
        elif command == 'S':
            self.s, self.u, self.n, self.d = self.u, self.n, self.d, self.s
        else:
            self.s, self.u, self.n, self.d = self.d, self.s, self.u, self.n

U, S, E, W, N, D = [int(i) for i in input().split()]
commands = input()
dice1 = Dice(U, S, E, W, N, D)
for command in commands:
    dice1.roll(command)
print(dice1.u)

Submission status: Accepted

Solution code:
class Dice:
    def __init__(self, label):
        self.label = label
    
    def rotateS(self):
        """[1, 2, 6, 5] -> [5, 1, 2, 6]"""
        t = self.label[1]
        self.label[1] = self.label[5]
        self.label[5] = self.label[6]
        self.label[6] = self.label[2]
        self.label[2] = t

    def rotateN(self):
        t = self.label[1]
        self.label[1] = self.label[2]
        self.label[2] = self.label[6]
        self.label[6] = self.label[5]
        self.label[5] = t
    
    def rotateW(self):
        t = self.label[1]
        self.label[1] = self.label[3]
        self.label[3] = self.label[6]
        self.label[6] = self.label[4]
        self.label[4] = t
    
    def rotateE(self):
        t = self.label[1]
        self.label[1] = self.label[4]
        self.label[4] = self.label[6]
        self.label[6] = self.label[3]
        self.label[3] = t

label = []
label.append(None)
label[1:] = map(int,input().split())
dice = Dice(label)
#print(dice.label)

cmd = input()
for _ in cmd:
    if (_ == 'S'):
        dice.rotateS()
    elif (_ == 'N'):
        dice.rotateN()
    elif (_ == 'W'):
        dice.rotateW()
    elif (_ == 'E'):
        dice.rotateE()
print(dice.label[1])

Submission status: Accepted

Solution code:
D = [
    (1, 5, 2, 3, 0, 4), # 'U'
    (3, 1, 0, 5, 4, 2), # 'R'
    (4, 0, 2, 3, 5, 1), # 'D'
    (2, 1, 5, 0, 4, 3), # 'L'
]
C = 'NESW'

*L, = map(int, input().split())
for c in input():
    L[:] = (L[e] for e in D[C.index(c)])
print(L[0])

Submission status: Accepted

Solution code:
class Dice:
    def __init__(self, top, front, right, left, back, bottom):
        self.TOP = top
        self.BOTTOM = bottom
        self.FRONT = front
        self.BACK = back
        self.LEFT = left
        self.RIGHT = right
    
    def move_N(self):
        tmp = self.TOP
        self.TOP = self.FRONT
        self.FRONT = self.BOTTOM
        self.BOTTOM = self.BACK
        self.BACK = tmp

    def move_S(self):
        tmp = self.TOP
        self.TOP = self.BACK
        self.BACK = self.BOTTOM
        self.BOTTOM = self.FRONT
        self.FRONT = tmp
        
    def move_W(self):
        tmp = self.TOP
        self.TOP = self.RIGHT
        self.RIGHT = self.BOTTOM
        self.BOTTOM = self.LEFT
        self.LEFT = tmp

    def move_E(self):
        tmp = self.TOP
        self.TOP = self.LEFT
        self.LEFT = self.BOTTOM
        self.BOTTOM = self.RIGHT
        self.RIGHT = tmp
    
    @property
    def top(self):
        return self.TOP
        
top, front, right, left, back, bottom = map(int,input().split())
dice = Dice(top, front, right, left, back, bottom)
m = input()
for i in range(len(m)):
    if m[i] == "N":
        dice.move_N()
    elif m[i] == "E":
        dice.move_E()
    elif m[i] == "S":
        dice.move_S()
    elif m[i] == "W":
        dice.move_W()
    else:
        raise Exception
print(dice.TOP)

Submission status: Accepted

Solution code:
class Dice:
    def __init__(self,u,w,s,e,n,d):
        self.u=u
        self.w=w
        self.s=s
        self.e=e
        self.n=n
        self.d=d

    def rot(self,way):

        if way=="W":
            c=self.u
            self.u=self.e
            self.e=self.d
            self.d=self.w
            self.w=c
        elif way=="S":
            c=self.u
            self.u=self.n
            self.n=self.d
            self.d=self.s
            self.s=c
        elif way=="E":
            c=self.u
            self.u=self.w
            self.w=self.d
            self.d=self.e
            self.e=c
        else:
            c=self.u
            self.u=self.s
            self.s=self.d
            self.d=self.n
            self.n=c

u,s,e,w,n,d=map(int,input().split())
dice=Dice(u,w,s,e,n,d)
st=input()
for c in st:
    dice.rot(c)
print(dice.u)

Submission status: Accepted

Solution code:
dice = list(map(int, input().split()))
com = input()
for i in range(len(com)):
    if com[i] == 'E':
        temp = dice[0]
        dice[0] = dice[3]
        dice[3] = dice[5]
        dice[5] = dice[2]
        dice[2] = temp
    elif com[i] == 'N':
        temp = dice[0]
        dice[0] = dice[1]
        dice[1] = dice[5]
        dice[5] = dice[4]
        dice[4] = temp
    elif com[i] == 'S':
        temp = dice[0]
        dice[0] = dice[4]
        dice[4] = dice[5]
        dice[5] = dice[1]
        dice[1] = temp
    else:
        temp = dice[0]
        dice[0] = dice[2]
        dice[2] = dice[5]
        dice[5] = dice[3]
        dice[3] = temp
print(dice[0])

Submission status: Accepted

Solution code:
class Dice:
    def __init__(self,num):
        self.top = num[0]
        self.front = num[1]
        self.right = num[2]
        self.left = num[3]
        self.back = num[4]
        self.bottom = num[5]

    def south_direction(self):
        front = self.top
        bottom = self.front
        back = self.bottom
        top = self.back
        right = self.right
        left = self.left
        
        self.top = top
        self.front = front
        self.bottom = bottom
        self.back = back
        self.right = right
        self.left = left

    def north_direction(self):
        back = self.top
        top = self.front
        front = self.bottom
        bottom = self.back
        right = self.right
        left = self.left
        
        self.top = top
        self.front = front
        self.bottom = bottom
        self.back = back
        self.right = right
        self.left = left

    def east_direction(self):
        right = self.top
        front = self.front
        left = self.bottom
        back = self.back
        bottom = self.right
        top = self.left
        
        self.top = top
        self.front = front
        self.bottom = bottom
        self.back = back
        self.right = right
        self.left = left
        
    def west_direction(self):
        left = self.top
        front = self.front
        right = self.bottom
        back = self.back
        top = self.right
        bottom = self.left
        
        self.top = top
        self.front = front
        self.bottom = bottom
        self.back = back
        self.right = right
        self.left = left
    
    def print_top(self):
        print(self.top)

num = list(map(int,input().split()))
directions = input()

d = Dice(num)
for i in directions:
    if i == "N":
        d.north_direction()
    elif i == "S":
        d.south_direction()
    elif i == "E":
        d.east_direction()
    elif i == "W":
        d.west_direction()

d.print_top()

Submission status: Accepted

Solution code:
l=list(map(int,input().split()))
s=input()
for i in s:
    if i=="W":
        l[0],l[2],l[5],l[3]=l[2],l[5],l[3],l[0]
    elif i=="E":
        l[0],l[2],l[5],l[3]=l[3],l[0],l[2],l[5]
    elif i=="N":
        l[0],l[1],l[5],l[4]=l[1],l[5],l[4],l[0]
    else:
        l[0],l[1],l[5],l[4]=l[4],l[0],l[1],l[5]
print(l[0])

Submission status: Accepted

Solution code:
class dice():
    def __init__(self):
        self.number = [i for i in range(6)]
        self.work = [i for i in range(6)]
    
    def setnum(self,s):
        self.number = s

    def kai(self,h):
        tmp = self.number
        if h == 'E':
            self.number = [tmp[3],tmp[1],tmp[0],tmp[5],tmp[4],tmp[2]]
        elif h == 'S':
            self.number = [tmp[4],tmp[0],tmp[2],tmp[3],tmp[5],tmp[1]]
        elif h == 'W':
            self.number = [tmp[2],tmp[1],tmp[5],tmp[0],tmp[4],tmp[3]]
        elif h == 'N':
            self.number = [tmp[1],tmp[5],tmp[2],tmp[3],tmp[0],tmp[4]]

num = list(map(int,input().split()))
kaitenn = input()
dice = dice()
dice.setnum(num)
for i in range(len(kaitenn)):
    dice.kai(kaitenn[i])
print(dice.number[0])

Submission status: Accepted

Solution code:
N=list(map(int,input().split()))
D=input()
for d in D:
  if d=="E":
    N=[N[3],N[1],N[0],N[5],N[4],N[2]]
  if d=="W":
    N=[N[2],N[1],N[5],N[0],N[4],N[3]]
  if d=="N":
    N=[N[1],N[5],N[2],N[3],N[0],N[4]]
  if d=="S":
    N=[N[4],N[0],N[2],N[3],N[5],N[1]]
print(N[0])

Submission status: Accepted

Solution code:
class Dice:
    def __init__(self, labels):
        self.surface = {x: labels[x-1] for x in range(1, 6+1)}
    def move_towards(self, direction):
        if direction == 'N':
            self._move(1, 2, 6, 5)
        elif direction == 'S':
            self._move(1, 5, 6, 2)
        elif direction == 'E':
            self._move(1, 4, 6, 3)
        elif direction == 'W':
            self._move(1, 3, 6, 4)
    def get_upper(self):
        return self.surface[1]
    def _move(self, i, j, k, l):
        temp_label = self.surface[i]
        self.surface[i] = self.surface[j]
        self.surface[j] = self.surface[k]
        self.surface[k] = self.surface[l]
        self.surface[l] = temp_label

labels = list(map(int, input().split()))
dice = Dice(labels)
moves = input()
for move in moves:
    dice.move_towards(move)
print(dice.get_upper())

Submission status: Accepted

Solution code:
dice = list(map(int, input().split()))
directions = input()


class Dice():
    def __init__(self, dice, directions):
        self.dice = dice
        self.directions = directions

    def get_top(self):
        for direction in self.directions:
            NS = [0, 1, 5, 4]
            WE = [0, 2, 5, 3]
            copy_dice = self.dice[:]

            if direction == 'N':
                for j in range(4):
                    self.dice[NS[j]] = copy_dice[NS[j-3]]
            elif direction == 'S':
                for j in range(4):
                    self.dice[NS[j]] = copy_dice[NS[j-1]]
            elif direction == 'W':
                for j in range(4):
                    self.dice[WE[j]] = copy_dice[WE[j-3]]
            else:
                for j in range(4):
                    self.dice[WE[j]] = copy_dice[WE[j-1]]

        return self.dice[0]

dice_roll = Dice(dice, directions)

print(dice_roll.get_top())

Submission status: Accepted

Solution code:
top, back, right, left, front, bottom = [int(i) for i in input().split()]
for i in input():
    if i == "N":
        top, front, bottom, back = back, top, front, bottom
    elif i == "S":
        top, front, bottom, back = front, bottom, back, top
    elif i == "E":
        top, left, bottom, right = left, bottom, right, top
    else:
        top, left, bottom, right = right, top, left, bottom
print(top)

Submission status: Accepted

Solution code:
#coding: utf-8

nesw = {'N':0, 'E':1, 'S':2, 'W':3}
dirc = ((4, 0, 2, 3, 5, 1), (2, 1, 5, 0, 4, 3),
(1, 5, 2, 3, 0, 4), (3, 1, 0, 5, 4, 2))
dice = [0, 1, 2, 3, 4, 5]
temp = [0 for i in range(6)]

label = list(map(int, input().split()))
order = input()

for i in order:
    for j in range(6):
        temp[dirc[nesw[i]][j]] = dice[j]
    dice = temp[:]
print(label[dice[0]])

Submission status: Accepted

Solution code:
class Dice:
    def __init__(self, default = [1, 2, 3, 4, 5, 6]):
        self.d = default

    def e(self):
        self.d[0], self.d[2], self.d[3], self.d[5] = self.d[3], self.d[0], self.d[5], self.d[2]

    def w(self):
        self.d[0], self.d[2], self.d[3], self.d[5] = self.d[2], self.d[5], self.d[0], self.d[3]

    def n(self):
        self.d[0], self.d[1], self.d[4], self.d[5] = self.d[1], self.d[5], self.d[0], self.d[4]

    def s(self):
        self.d[0], self.d[1], self.d[4], self.d[5] = self.d[4], self.d[0], self.d[5], self.d[1]

    def top(self):
        return self.d[0]


def main():
    dice = Dice([int(i) for i in input().split()])
    for o in input():
        if o == 'E':
            dice.e()
        elif o == 'W':
            dice.w()
        elif o == 'S':
            dice.s()
        else:
            dice.n()

    print(dice.top())


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
class Dice:
    #f[]はUSEWNDの順，添字はU:0,S:1,E:2,W:3,N:4,D:5
    def __init__(self,l):
        self.f=l
        
    def __str__(self):
        l=self.f
        s=f'[U:{l[0]},S:{l[1]},E:{l[2]},W:{l[3]},N:{l[4]},D:{l[5]}]'
        return(s)
       
    def roll(self,c):
        if c=='N':
            ni=[1,5,2,3,0,4]
        elif c=='S':
            ni=[4,0,2,3,5,1]
        elif c=='E':
            ni=[3,1,0,5,4,2]
        elif c=='W':
            ni=[2,1,5,0,4,3]
        self.f=[self.f[j] for j in ni]
    
    def rotate(self,r):
        if r==+1: #Uから見て反時計(西)回り
            ni=[0,3,1,4,2,5]
        elif r==-1: #Uから見て時計(東)周り
            ni=[0,2,4,1,3,5]
        self.f=[self.f[j] for j in ni]

d=Dice(list(map(int,input().split())))
for c in input():
    d.roll(c)
print(d.f[0])

Submission status: Accepted

Solution code:
class Dice:
    def __init__(self,list):
        self.list = []
        for i in range(6):
            self.list.append(list[i])

    def rotate(self,dir):
        if dir == "N":
            self.list[0], self.list[1], self.list[5], self.list[4] = self.list[1], self.list[5], self.list[4], self.list[0]
        elif dir == "S":
            self.list[0], self.list[4], self.list[5], self.list[1] = self.list[4], self.list[5], self.list[1], self.list[0]
        elif dir == "W":
            self.list[0], self.list[3], self.list[5], self.list[2] = self.list[2], self.list[0], self.list[3], self.list[5]
        elif dir == "E":
            self.list[0], self.list[3], self.list[5], self.list[2] = self.list[3], self.list[5], self.list[2], self.list[0]
        else:
            pass

    def show(self):
        for i in self.list:
            print(i)


l = [ int(x) for x in input().split()]
dice = Dice(l)
str = input()
for i in range(len(str)):
    dice.rotate(str[i])
print(dice.list[0])

Submission status: Accepted

Solution code:
class Sai():
    def __init__(self, m1, m2, m3, m4, m5, m6):
        self.t = m1
        self.s = m2
        self.e = m3
        self.w = m4
        self.n = m5
        self.b = m6
    def furu(self, arg):
        if arg == 'N':
            tmp = self.s
            self.s = self.b
            self.b = self.n
            self.n = self.t
            self.t = tmp
        elif arg == 'S':
            tmp = self.n
            self.n = self.b
            self.b = self.s
            self.s = self.t
            self.t = tmp
        elif arg == 'W':
            tmp = self.e
            self.e = self.b
            self.b = self.w
            self.w = self.t
            self.t = tmp
        else:
            tmp = self.w
            self.w = self.b
            self.b = self.e
            self.e = self.t
            self.t = tmp

s = list(map(int, input().split()))
c = input()
sai = Sai(s[0], s[1], s[2], s[3], s[4], s[5])
for i in c:
    sai.furu(i)
    
print(sai.t)

Submission status: Accepted

Solution code:
def dice(u,f,o):
	if u == 1 :
		if f == 2:
			if o == "E":
				u = 4
			if o == "N":
				u = 2
				f = 6
			if o == "S":
				u = 5
				f = 1
			if o == "W":
				u = 3
		elif f == 3:
			if o == "E":
				u = 2
			if o == "N":
				u = 3
				f = 6
			if o == "S":
				u = 4
				f = 1
			if o == "W":
				u = 5
		elif f == 5:
			if o == "E":
				u = 3
			if o == "N":
				u = 5
				f = 6
			if o == "S":
				u = 2
				f = 1
			if o == "W":
				u = 4
		elif f == 4:
			if o == "E":
				u = 5
			if o == "N":
				u = 4
				f = 6
			if o == "S":
				u = 3
				f = 1
			if o == "W":
				u = 2
	elif u == 2 :
		if f == 1:
			if o == "E":
				u = 3
			if o == "N":
				u = 1
				f = 5
			if o == "S":
				u = 6
				f = 2
			if o == "W":
				u = 4
		elif f == 3:
			if o == "E":
				u = 6
			if o == "N":
				u = 3
				f = 5
			if o == "S":
				u = 4
				f = 2
			if o == "W":
				u = 1
		elif f == 4:
			if o == "E":
				u = 1
			if o == "N":
				u = 4
				f = 5
			if o == "S":
				u = 3
				f = 2
			if o == "W":
				u = 6
		elif f == 6:
			if o == "E":
				u = 4
			if o == "N":
				u = 6
				f = 5
			if o == "S":
				u = 1
				f = 2
			if o == "W":
				u = 3
	elif u == 3 :
		if f == 2:
			if o == "E":
				u = 1
			if o == "N":
				u = 2
				f = 4
			if o == "S":
				u = 5
				f = 3
			if o == "W":
				u = 6
		elif f == 1:
			if o == "E":
				u = 5
			if o == "N":
				u = 1
				f = 4
			if o == "S":
				u = 6
				f = 3
			if o == "W":
				u = 2
		elif f == 5:
			if o == "E":
				u = 6
			if o == "N":
				u = 5
				f = 4
			if o == "S":
				u = 2
				f = 3
			if o == "W":
				u = 1
		elif f == 6:
			if o == "E":
				u = 2
			if o == "N":
				u = 6
				f = 4
			if o == "S":
				u = 1
				f = 3
			if o == "W":
				u = 5
	elif u == 4 :
		if f == 1:
			if o == "E":
				u = 2
			if o == "N":
				u = 1
				f = 3
			if o == "S":
				u = 6
				f = 4
			if o == "W":
				u = 5
		elif f == 2:
			if o == "E":
				u = 6
			if o == "N":
				u = 2
				f = 3
			if o == "S":
				u = 5
				f = 4
			if o == "W":
				u = 1
		elif f == 5:
			if o == "E":
				u = 1
			if o == "N":
				u = 5
				f = 3
			if o == "S":
				u = 2
				f = 4
			if o == "W":
				u = 6
		elif f == 6:
			if o == "E":
				u = 5
			if o == "N":
				u = 6
				f = 3
			if o == "S":
				u = 1
				f = 4
			if o == "W":
				u = 2
	elif u == 5 :
		if f == 1:
			if o == "E":
				u = 4
			if o == "N":
				u = 1
				f = 2
			if o == "S":
				u = 6
				f = 5
			if o == "W":
				u = 3
		elif f == 3:
			if o == "E":
				u = 1
			if o == "N":
				u = 3
				f = 2
			if o == "S":
				u = 4
				f = 5
			if o == "W":
				u = 6
		elif f == 4:
			if o == "E":
				u = 6
			if o == "N":
				u = 4
				f = 2
			if o == "S":
				u = 3
				f = 5
			if o == "W":
				u = 1
		elif f == 6:
			if o == "E":
				u = 3
			if o == "N":
				u = 6
				f = 2
			if o == "S":
				u = 1
				f = 5
			if o == "W":
				u = 4
	elif u == 6 :
		if f == 2:
			if o == "E":
				u = 3
			if o == "N":
				u = 2
				f = 1
			if o == "S":
				u = 5
				f = 6
			if o == "W":
				u = 4
		elif f == 3:
			if o == "E":
				u = 5
			if o == "N":
				u = 3
				f = 1
			if o == "S":
				u = 4
				f = 6
			if o == "W":
				u = 2
		elif f == 4:
			if o == "E":
				u = 2
			if o == "N":
				u = 4
				f = 1
			if o == "S":
				u = 3
				f = 6
			if o == "W":
				u = 5
		elif f == 5:
			if o == "E":
				u = 4
			if o == "N":
				u = 5
				f = 1
			if o == "S":
				u = 2
				f = 6
			if o == "W":
				u = 3
	return [u,f]
n = list(map(int,input().split()))
o_list = list(input())
o_length = len(o_list)
u = 1 
f = 2
for i in range(o_length):
	a = dice(u,f,o_list[i])
	u = a[0]
	f = a[1]

print(n[u-1])