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:
def north(d):
    d[0], d[1], d[5], d[4] = d[1], d[5], d[4], d[0]


def west(d):
    d[0], d[2], d[5], d[3] = d[2], d[5], d[3], d[0]


def east(d):
    d[0], d[3], d[5], d[2] = d[3], d[5], d[2], d[0]


def south(d):
    d[0], d[4], d[5], d[1] = d[4], d[5], d[1], d[0]


F = {'N': north, 'W': west, 'E': east, 'S': south}
d, os = list(map(int, input().split())), input()
for o in os:
    F[o](d)
print(d[0])

Submission status: Accepted

Solution code:
class Dice:
    def __init__(self,l1,l2,l3,l4,l5,l6):
        self.l1 = l1
        self.l2 = l2
        self.l3 = l3
        self.l4 = l4
        self.l5 = l5
        self.l6 = l6
        self.top = 1
        self.front = 2
        self.right = 3

    def get_top(self):
        return eval("self." + 'l' + str(self.top))

    def move(self, order):
        if order == 'S':
            pretop = self.top
            self.top = 7 - self.front
            self.front = pretop
        elif order == 'E':
            pretop = self.top
            self.top = 7 - self.right
            self.right = pretop
        elif order == 'N':
            pretop = self.top
            self.top = self.front
            self.front = 7 - pretop
        elif order == 'W':
            pretop = self.top
            self.top = self.right
            self.right = 7 - pretop

l = list(map(int,input().split()))
orders = input()
d = Dice(l[0],l[1],l[2],l[3],l[4],l[5])
for order in orders:
    d.move(order)
print(d.get_top())

Submission status: Accepted

Solution code:


u,s,e,w,n,b = map(int,input().split())
roll = input()
for i in roll:
	if i == "E":
		tmp = e
		e = u
		u = w
		w = b
		b = tmp
	elif i == "S":
		tmp = s
		s = u
		u = n
		n = b
		b = tmp
	elif i == "W":
		tmp = w
		w = u
		u = e
		e = b
		b = tmp
	elif i == "N":
		tmp = n
		n = u
		u = s
		s = b
		b = tmp

print(u)

Submission status: Accepted

Solution code:
def move(up,bottom,right,left,front,back,direction):
    if direction == "N":
        return (front,back,right,left,bottom,up)
    elif direction == "S":
        return (back,front,right,left,up,bottom)
    elif direction == "E":
        return (left,right,up,bottom,front,back)
    elif direction == "W":
        return (right,left,bottom,up,front,back)
    
up,front,right,left,back,bottom = input().split()
direction = list(input())

for i in range(len(direction)):
    up,bottom,right,left,front,back = move(up,bottom,right,left,front,back,direction[i])
    
print(up)

Submission status: Accepted

Solution code:


u, s, e, w, n, b = map(int, input().split())
roll = input()
for i in roll:
    if i == "E":
        e,u,w,b = u,w,b,e
    elif i == "S":
        s,u,n,b = u,n,b,s
    elif i == "W":
        w,u,e,b = u,e,b,w
    elif i == "N":
        n,u,s,b = u,s,b,n
print(u)

Submission status: Accepted

Solution code:
class Dice:
    u, s, e, w, n, b = map(int, input().split())
    roll = input()
    for i in roll:
        if i == "E":
            e,u,w,b = u,w,b,e
        elif i == "S":
            s,u,n,b = u,n,b,s
        elif i == "W":
            w,u,e,b = u,e,b,w
        elif i == "N":
            n,u,s,b = u,s,b,n
    print(u)

dice = Dice()

Submission status: Accepted

Solution code:
r={'N':(1,5,2,3,0,4),'S':(4,0,2,3,5,1),'E':(3,1,0,5,4,2),'W':(2,1,5,0,4,3)}
d=input().split()
for x in input():
    d=[d[y]for y in r[x]]
print(d[0])

Submission status: Accepted

Solution code:
#!usr/bin/env python3

import sys


class Die:
    def __init__(self, pips):
        self.pips = pips

    def move_die(self, direction):
        tmp = int()
        if direction == 'N':
            tmp = self.pips[0]
            self.pips[0] = self.pips[1]
            self.pips[1] = self.pips[5]
            self.pips[5] = self.pips[4]
            self.pips[4] = tmp
        elif direction == 'S':
            tmp = self.pips[0]
            self.pips[0] = self.pips[4]
            self.pips[4] = self.pips[5]
            self.pips[5] = self.pips[1]
            self.pips[1] = tmp
        elif direction == 'E':
            tmp = self.pips[0]
            self.pips[0] = self.pips[3]
            self.pips[3] = self.pips[5]
            self.pips[5] = self.pips[2]
            self.pips[2] = tmp
        elif direction == 'W':
            tmp = self.pips[0]
            self.pips[0] = self.pips[2]
            self.pips[2] = self.pips[5]
            self.pips[5] = self.pips[3]
            self.pips[3] = tmp

    def print_upside(self):
        print(self.pips[0])


def main():
    pips = [int(pip) for pip in sys.stdin.readline().strip('\n').split()]
    die = Die(pips)
    directions = list(sys.stdin.readline().strip('\n'))

    for direction in directions:
        die.move_die(direction)

    die.print_upside()


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
#!usr/bin/env python3

import sys


class Die:
    def __init__(self, pips):
        self.pips = pips

    def move_die(self, direction):
        tmp = int()
        if direction == 'N':
            tmp = self.pips[0]
            self.pips[0] = self.pips[1]
            self.pips[1] = self.pips[5]
            self.pips[5] = self.pips[4]
            self.pips[4] = tmp
        elif direction == 'S':
            tmp = self.pips[0]
            self.pips[0] = self.pips[4]
            self.pips[4] = self.pips[5]
            self.pips[5] = self.pips[1]
            self.pips[1] = tmp
        elif direction == 'E':
            tmp = self.pips[0]
            self.pips[0] = self.pips[3]
            self.pips[3] = self.pips[5]
            self.pips[5] = self.pips[2]
            self.pips[2] = tmp
        elif direction == 'W':
            tmp = self.pips[0]
            self.pips[0] = self.pips[2]
            self.pips[2] = self.pips[5]
            self.pips[5] = self.pips[3]
            self.pips[3] = tmp

    def get_upside(self):
        return self.pips[0]


def init_die():
    pips = [int(pip) for pip in sys.stdin.readline().strip('\n').split()]
    die = Die(pips)
    return die


def roll_die(die):
    directions = list(sys.stdin.readline().strip('\n'))

    for direction in directions:
        die.move_die(direction)

    return die


def main():
    die = init_die()
    die = roll_die(die)
    print(die.get_upside())


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
class Dice():
	def __init__(self, label):
		self.d = label
	
	def roll(self, drt):
		if drt == 'N':
			self.d[1], self.d[2], self.d[6], self.d[5] = self.d[2], self.d[6], self.d[5], self.d[1]
		elif drt == 'E':
			self.d[1], self.d[3], self.d[6], self.d[4] = self.d[4], self.d[1], self.d[3], self.d[6]
		elif drt == 'S':
			self.d[2], self.d[6], self.d[5], self.d[1] = self.d[1], self.d[2], self.d[6], self.d[5]
		elif drt == 'W':
			self.d[4], self.d[1], self.d[3], self.d[6] = self.d[1], self.d[3], self.d[6], self.d[4]
	def printl(self, lct):
		print(self.d[lct])
		
label = [0]	
label.extend(list(map(int, input().split())))
dice1 = Dice(label)
direction = input()
leng = len(direction)

for i in range(leng):
	dice1.roll(direction[i])

dice1.printl(1)

Submission status: Accepted

Solution code:
A,B,C,D,E,F = map(int, input().split())
f = list(input())
for i in range(len(f)):
    if f[i] == "E":
        A,B,C,D,E,F = D,B,A,F,E,C
    elif f[i] == "N":
        A,B,C,D,E,F = B,F,C,D,A,E
    elif f[i] == "S":
        A,B,C,D,E,F = E,A,C,D,F,B
    elif f[i] == "W":
        A,B,C,D,E,F = C,B,F,A,E,D

print(A)

Submission status: Accepted

Solution code:
d = map(int,raw_input().split())
#m = {"E":[4,2,1,6,5,3],"N":[2,6,3,4,1,5],"W":[3,2,6,1,5,4],"S":[5,1,3,4,6,2]}
m = {"E":[3,1,0,5,4,2],"N":[1,5,2,3,0,4],"W":[2,1,5,0,4,3],"S":[4,0,2,3,5,1]}

nd = [0]*6
for x in raw_input():
    for j in range(6):
        nd[j] = d[m[x][j]]
    d = list(nd)
print d[0]

Submission status: Accepted

Solution code:
class Dice:
    """Dice class"""

    def __init__(self):                  # ?????????????????????
        self.eyeIndex = 1        #center
        self.eyeIndex_E = 3      #east
        self.eyeIndex_W = 4      #west
        self.eyeIndex_N = 5      #north
        self.eyeIndex_S = 2      #south
        self.eye = 0
        
    def shakeDice(self, in_command):

        pre_eyeIndex = self.eyeIndex
        if in_command == "E":
            self.eyeIndex = self.eyeIndex_W 
            self.eyeIndex_E = pre_eyeIndex 
            self.eyeIndex_W = 7 - self.eyeIndex_E
            
        elif in_command == "W":
            self.eyeIndex = self.eyeIndex_E 
            self.eyeIndex_W = pre_eyeIndex
            self.eyeIndex_E = 7 - self.eyeIndex_W
            
        elif in_command == "N":
            self.eyeIndex = self.eyeIndex_S 
            self.eyeIndex_N = pre_eyeIndex 
            self.eyeIndex_S = 7 - self.eyeIndex_N

        elif in_command == "S":
            self.eyeIndex = self.eyeIndex_N         
            self.eyeIndex_S = pre_eyeIndex 
            self.eyeIndex_N = 7 - self.eyeIndex_S 
            
        self.eye = self.eyes[self.eyeIndex]

    def getEye(self):
        return self.eye

    def setEyes(self, eyes):             # setEyes()???????????? ???????????????
        
        #index???1???????????????????????§,??????????????????????????????
        eyes = "0 " + eyes
        self.eyes = list(map(int, eyes.split(" ")))


dice_1 = Dice()
dice_1.setEyes(input().rstrip())

input_commands = input().rstrip()

for i in range(len(input_commands)):
    #Shake dice!!
    dice_1.shakeDice(input_commands[i])

print(dice_1.getEye())

Submission status: Accepted

Solution code:
class dice:
    def __init__(self, pip):
        self.pip = pip
        
    def move(self,dir):
        if str(dir) == "E":
            self.pip[0],self.pip[2],self.pip[3],self.pip[5] = self.pip[3],self.pip[0],self.pip[5],self.pip[2]
        elif str(dir) == "W":
            self.pip[0],self.pip[2],self.pip[3],self.pip[5] = self.pip[2],self.pip[5],self.pip[0],self.pip[3]
        elif str(dir) == "N":
            self.pip[0],self.pip[1],self.pip[4],self.pip[5] = self.pip[1],self.pip[5],self.pip[0],self.pip[4]
        elif str(dir) == "S":
            self.pip[0],self.pip[1],self.pip[4],self.pip[5] = self.pip[4],self.pip[0],self.pip[5],self.pip[1]

d = dice(list(map(int,input().split())))
inp = list(input())

for dir in inp:
    d.move(dir)

print(d.pip[0])

Submission status: Accepted

Solution code:
number = [int(x) for x in input().split()]
#S
#1 -> 2
#2 -> 6
#3 -> 3
#4 -> 4
#5 -> 1
#6 -> 5
order = input()

for i in range(len(order)):
    number_2 = [number[i] for i in range(len(number))]
    if order[i] == 'S':
        number[0] = number_2[4]
        number[1] = number_2[0]
        number[4] = number_2[5]
        number[5] = number_2[1]
    if order[i] == 'W':
        number[0] = number_2[2]
        number[2] = number_2[5]
        number[3] = number_2[0]
        number[5] = number_2[3]
    if order[i] == 'E':
        number[0] = number_2[3]
        number[2] = number_2[0]
        number[3] = number_2[5]
        number[5] = number_2[2]
    if order[i] == 'N':
        number[0] = number_2[1]
        number[1] = number_2[5]
        number[4] = number_2[0]
        number[5] = number_2[4]
    #print(number)

print(number[0])

Submission status: Accepted

Solution code:
class Dice:
    def __init__(self):
        self.faces=[]

    def rotate(self, direction):
        tmp = self.faces.copy()

        if direction =="N":
            self.faces[5-1] = tmp[1-1]
            self.faces[1-1] = tmp[2-1]
            self.faces[2-1] = tmp[6-1]
            self.faces[6-1] = tmp[5-1]
        if direction =="S":
            self.faces[5-1] = tmp[6-1]
            self.faces[1-1] = tmp[5-1]
            self.faces[2-1] = tmp[1-1]
            self.faces[6-1] = tmp[2-1]
        if direction =="W":
            self.faces[4-1] = tmp[1-1]
            self.faces[1-1] = tmp[3-1]
            self.faces[3-1] = tmp[6-1]
            self.faces[6-1] = tmp[4-1]
        if direction =="E":
            self.faces[3-1] = tmp[1-1]
            self.faces[1-1] = tmp[4-1]
            self.faces[4-1] = tmp[6-1]
            self.faces[6-1] = tmp[3-1]
        return 0



d1 = Dice()
d1.faces=[int(x) for x in input().split(" ")]
directions=list(input())
for d in directions:
    d1.rotate(d)
print(d1.faces[0])

Submission status: Accepted

Solution code:
inp = [i for i in input().split()]
com = input()
for i in range(len(com)):
    if com[i] == "N":
        a = []
        a.append(inp[1])
        a.append(inp[5])
        a.append(inp[2])
        a.append(inp[3])
        a.append(inp[0])
        a.append(inp[4])
        inp = a
    elif com[i] == "S":
        a = []
        a.append(inp[4])
        a.append(inp[0])
        a.append(inp[2])
        a.append(inp[3])
        a.append(inp[5])
        a.append(inp[1])
        inp = a
    elif com[i] == "E":
        a = []
        a.append(inp[3])
        a.append(inp[1])
        a.append(inp[0])
        a.append(inp[5])
        a.append(inp[4])
        a.append(inp[2])
        inp = a
    elif com[i] == "W":
        a = []
        a.append(inp[2])
        a.append(inp[1])
        a.append(inp[5])
        a.append(inp[0])
        a.append(inp[4])
        a.append(inp[3])
        inp = a
print(inp[0])

Submission status: Accepted

Solution code:

"""
DiceFaces : ?????????????????¢?????°???
    ?????????????????¢?????¶??? : [top, front, right, left, back, bottom]

Rotates : ?????¢????????????
"""

# ????????????????????¢??????????§?
EAST = "E"
WEST = "W"
SOUTH = "S"
NORTH = "N"

TOP = 0
FRONT = 1
RIGHT = 2
LEFT = 3
BACK = 4
BOTTOM = 5

def rotated_dice(DiceFaces, Rotate):
    """
    ????????????????????¢
    """
    if Rotate == EAST:
        # ??¢?????¶??? : [top, front, right, left, back, bottom] to [left, front, top, bottom, back, right]
        DiceFaces[TOP], DiceFaces[RIGHT], DiceFaces[LEFT], DiceFaces[BOTTOM] = DiceFaces[LEFT], DiceFaces[TOP], DiceFaces[BOTTOM], DiceFaces[RIGHT]
    elif Rotate == WEST:
        # ??¢?????¶??? : [top, front, right, left, back, bottom] to [right, front, bottom, top, back, left]
        DiceFaces[TOP], DiceFaces[RIGHT], DiceFaces[LEFT], DiceFaces[BOTTOM] = DiceFaces[RIGHT], DiceFaces[BOTTOM], DiceFaces[TOP], DiceFaces[LEFT]
    elif Rotate == SOUTH:
        # ??¢?????¶??? : [top, front, right, left, back, bottom] to [back, top, right, left, bottom, front]
        DiceFaces[TOP], DiceFaces[FRONT], DiceFaces[BACK], DiceFaces[BOTTOM] = DiceFaces[BACK], DiceFaces[TOP], DiceFaces[BOTTOM], DiceFaces[FRONT]
    elif Rotate == NORTH:
        # ??¢?????¶??? : [top, front, right, left, back, bottom] to [front, bottom, right, left, top, back]
        DiceFaces[TOP], DiceFaces[FRONT], DiceFaces[BACK], DiceFaces[BOTTOM] = DiceFaces[FRONT], DiceFaces[BOTTOM], DiceFaces[TOP], DiceFaces[BACK]

    return DiceFaces

if __name__ == "__main__":
    # ?????????????????¢?????°????????????
    DiceFaces = [int(x) for x in input().split(" ")]
    RotatesStirng = input()
    Rotates = [x for x in RotatesStirng]
    for Rotate in Rotates:
        DiceFaces = rotated_dice(DiceFaces, Rotate)

    print(DiceFaces[0])

Submission status: Accepted

Solution code:
class Dice:
    def __init__(self, usr_input, command):
        self.eyes = list(map(int, usr_input.split()))
        self.pos = {label:eye for label, eye in zip(range(1, 7), self.eyes)}
        self.com = list(command)

    def roll(self):
        for c in self.com:
            self.eyes = [n for n in self.pos.values()]
            if c == 'E':
                self.pos[1] = self.eyes[3]
                self.pos[3] = self.eyes[0]
                self.pos[4] = self.eyes[5]
                self.pos[6] = self.eyes[2]
            elif c == 'N':
                self.pos[1] = self.eyes[1]
                self.pos[2] = self.eyes[5]
                self.pos[5] = self.eyes[0]
                self.pos[6] = self.eyes[4]
            elif c == 'S':
                self.pos[1] = self.eyes[4]
                self.pos[2] = self.eyes[0]
                self.pos[5] = self.eyes[5]
                self.pos[6] = self.eyes[1]
            elif c == 'W':
                self.pos[1] = self.eyes[2]
                self.pos[3] = self.eyes[5]
                self.pos[4] = self.eyes[0]
                self.pos[6] = self.eyes[3]

    def top_print(self):
        print(self.pos.get(1))

if __name__ == '__main__':
    dice1 = Dice(input(), input())
    dice1.roll()
    dice1.top_print()

Submission status: Accepted

Solution code:
class Dice:
    def __init__(self, nums):
        self.nums = nums
    def rotate(self, direction):
        nums = self.nums
        if direction=="E":
            self.nums = [nums[3], nums[1], nums[0], nums[5], nums[4], nums[2]]
        elif direction=="W":
            self.nums = [nums[2], nums[1], nums[5], nums[0], nums[4], nums[3]]
        elif direction=="N":
            self.nums = [nums[1], nums[5], nums[2], nums[3], nums[0], nums[4]]
        elif direction=="S":
            self.nums = [nums[4], nums[0], nums[2], nums[3], nums[5], nums[1]]

    def upper_num(self):
        return self.nums[0]

dice = Dice(list(map(int, input().split())))
dirs = list(input())
for i in range(len(dirs)):
    dice.rotate(dirs[i])

print(dice.upper_num())

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-

import sys
import os
import math


dice = list(map(int, input().split()))
orders = input().strip()
for c in orders:
    copy = dice[:]
    if c == 'E':
        dice[2] = copy[0]
        dice[5] = copy[2]
        dice[3] = copy[5]
        dice[0] = copy[3]
    elif c == 'N':
        dice[0] = copy[1]
        dice[4] = copy[0]
        dice[5] = copy[4]
        dice[1] = copy[5]
        pass
    elif c == 'S':
        dice[1] = copy[0]
        dice[0] = copy[4]
        dice[4] = copy[5]
        dice[5] = copy[1]
    elif c == 'W':
        dice[0] = copy[2]
        dice[2] = copy[5]
        dice[5] = copy[3]
        dice[3] = copy[0]
print(dice[0])

Submission status: Accepted

Solution code:
dice = [1,2,3,4,5,6]
number = list(map(int,input().split()))
direction = str(input())

rotate_n =[2,6,3,4,1,5]
rotate_s =[5,1,3,4,6,2]
rotate_e =[4,2,1,6,5,3]
rotate_w =[3,2,6,1,5,4]

for i in direction:
    result = []
    if i == "N":
        for j in range(6):
            dice[j] = rotate_n[j]
    elif i == "S":
        for j in range(6):
            dice[j] = rotate_s[j]
    elif i == "E":
        for j in range(6):
            dice[j] = rotate_e[j]
    else:
        for j in range(6):
            dice[j] = rotate_w[j]
    for k in dice:
        result.append(number[k-1])
    number = result

print(number[0])

Submission status: Accepted

Solution code:
u,s,e,w,n,b = list(map(int, input().split()))
rolls = input()

for roll in rolls:
    if roll == 'N':
        n,u,e,w,b,s = u,s,e,w,n,b
    elif roll == 'S':
        s,b,e,w,u,n = u,s,e,w,n,b
    elif roll == 'E':
        e,s,b,u,n,w = u,s,e,w,n,b
    elif roll == 'W':
        w,s,u,b,n,e = u,s,e,w,n,b
    else:
        print('Error')
        raise(-1)

print(u)

Submission status: Accepted

Solution code:
class Dice:
    """????????????????????????"""
    def __init__(self, s):
        self.s1 = s[0]
        self.s2 = s[1]
        self.s3 = s[2]
        self.s4 = s[3]
        self.s5 = s[4]
        self.s6 = s[5]

    def roll(self, direction):          # ???????????????????§??????¢????????¢
        temp = self.s1
        if direction == "E":
            self.s1 = self.s4
            self.s4 = self.s6
            self.s6 = self.s3
            self.s3 = temp
        elif direction == "N":
            self.s1 = self.s2
            self.s2 = self.s6
            self.s6 = self.s5
            self.s5 = temp
        elif direction == "S":
            self.s1 = self.s5
            self.s5 = self.s6
            self.s6 = self.s2
            self.s2 = temp
        elif direction == "W":
            self.s1 = self.s3
            self.s3 = self.s6
            self.s6 = self.s4
            self.s4 = temp

s = list(map(int, input().split()))
dice1 = Dice(s)
command = input()

for i in range(len(command)):
    dice1.roll(command[i])

print(dice1.s1)

Submission status: Accepted

Solution code:
''' This is AOJ Practice. '''


class Dice:
    ''' Dice
    6??¢????????????????????¨??????????????§??????
    NWSE?????????????????????????????¨????????\?????????
    ?????????Top??????????????????????????¢??????????????????????????¨????????\?????????
    '''

    def __init__(self):
        ''' ????????????????????? '''
        self.axis1 = list()
        self.axis2 = list()
        self.init()

    def control_n(self):
        ''' ????????¢?????? '''
        bottom_value = self.axis2[3]
        top_value = self.axis2[1]
        self.axis2 = [bottom_value, self.axis2[0], top_value, self.axis2[2], bottom_value]
        self.axis1 = [bottom_value, self.axis1[1], top_value, self.axis1[3], bottom_value]

    def control_w(self):
        ''' ????????¢?????? '''
        bottom_value = self.axis1[1]
        top_value = self.axis1[3]
        self.axis2 = [bottom_value, self.axis2[1], top_value, self.axis2[3], bottom_value]
        self.axis1 = [bottom_value, self.axis1[2], top_value, self.axis1[4], bottom_value]

    def control_s(self):
        ''' ????????¢?????? '''
        bottom_value = self.axis2[1]
        top_value = self.axis2[3]
        self.axis2 = [bottom_value, self.axis2[2], top_value, self.axis2[4], bottom_value]
        self.axis1 = [bottom_value, self.axis1[1], top_value, self.axis1[3], bottom_value]

    def control_e(self):
        ''' ????????¢?????? '''
        bottom_value = self.axis1[3]
        top_value = self.axis1[1]
        self.axis2 = [bottom_value, self.axis2[1], top_value, self.axis2[3], bottom_value]
        self.axis1 = [bottom_value, self.axis1[0], top_value, self.axis1[2], bottom_value]

    def top(self):
        ''' ????????¢??????????????? '''
        return self.axis1[2]

    def control(self, word):
        ''' ?????????????????????
        Args
            word    ????????????
                N   ????????¢??????
                W   ????????¢??????
                S   ????????¢??????
                E   ????????¢??????
        '''
        if word == 'N':
            self.control_n()
        elif word == 'W':
            self.control_w()
        elif word == 'S':
            self.control_s()
        elif word == 'E':
            self.control_e()
        else:
            Exception()

    def show(self):
        ''' ?????¨?????±????¨???????????????? '''
        print(self.axis1)
        print(self.axis2)

    def init(self):
        ''' ??????????????? '''
        self.axis1 = [6, 4, 1, 3, 6]
        self.axis2 = [6, 2, 1, 5, 6]

if __name__ == '__main__':
    input_value = input()
    control_value = input()
    dice = Dice()

    for word in list(control_value):
        dice.control(word)

    print(input_value.split(" ")[dice.top()-1])

Submission status: Accepted

Solution code:
# coding: utf-8
# Here your code !
import sys
import collections
import unittest

def top_face_after_rolling_dice():
    try:
        faces    = [int(num) for num in input().rstrip().split()]
        rollings = input().rstrip()
    except:
        return __input_error()

    dice = CubicArbitraryValueDice(faces[0], faces[1], faces[2], faces[3], faces[4], faces[5])
    dice.put(dice.TOP, dice.SOUTH, dice.EAST, dice.WEST, dice.NORTH, dice.BOTTOM)
    
    for direction in rollings:
        dice.roll(direction)

    print(dice.faces[dice.direction[dice.TOP]])

class CubicArbitraryValueDice():
    TOP    = "top"
    BOTTOM = "bottom"
    EAST   = "E"
    WEST   = "W"
    SOUTH  = "S"
    NORTH  = "N"
    OPOSITE_DIRECTION_PAIRS = ( (EAST, WEST), (SOUTH, NORTH) )
    
    #??¢???index??§???????????????????????????
    def __init__(self, n_f0, n_f1, n_f2, n_f3, n_f4, n_f5):
        self.faces = [n_f0, n_f1, n_f2, n_f3, n_f4, n_f5]

    #???????????¢???index?????¢??£??????
    def put(self, dir_f0, dir_f1, dir_f2, dir_f3, dir_f4, dir_f5):  #?????°????????£?????????
        self.direction = { dir_fi : i for i,dir_fi in enumerate([dir_f0, dir_f1, dir_f2, dir_f3, dir_f4, dir_f5]) }

    #??¢???index????????´
    def roll(self, direction) : #dirction: (EAST, WEST, SOUTH, NORTH) ??????????????????
        for pair in self.OPOSITE_DIRECTION_PAIRS :
            if direction in pair :
                oposite = pair[0] if (pair[1] == direction) else pair[1]
        
        current = {}
        for direct in (self.TOP, self.BOTTOM, direction, oposite):
            current.update({direct : self.direction[direct]})

        #            direction to bottom,       bottom to oposite,      oposite to top,     top to direction 
        for pair in ((direction, self.BOTTOM), (self.BOTTOM, oposite), (oposite, self.TOP), (self.TOP, direction)):
            self.direction[pair[1]] = current[pair[0]]

def __input_error():
    print("input error")
    return -1
'''
class __TestValueClass(unittest.TestCase):
    def testEqual(self, func, tuples, eff_digit = math.nan, print_success = False):
        self.testFunction(self.assertEqual,func,tuples,eff_digit,print_success)
    
    def testFunction(self,assertfunc,func,tuples,eff_digit,print_success):
        #tuples[index] = ([*arguments of func], compared value)
        for item in tuples:
            try:
                if isinstance(item[0], collections.Iterable):
                    value = func(*item[0])
                else:
                    value = func(item[0])
                
                if math.isnan(eff_digit) :
                    assertfunc(value,item[1])
                else :
                    format_str = "{0:."+str(eff_digit)+"g}"
                    assertfunc(format_str.format(value),format_str.format(item[1]))
                    
            except Exception as msg:
                swidth = 15
                print("="*50)
                print("-- Assertion Error in '" + func.__name__ + "' --")
                info = []
                info.append(["arguments"     , item[0]    ])
                info.append(["compared value", item[1]    ])
                info.append(["message"       , "\n" + msg ])
                for state in info :
                    print(state[0].ljust(swidth) + ":", state[1])
                sys.exit()

        if print_success :
            print(func.__name__,": succeeded")
'''
#test
if __name__ == "__main__" :
#    test = __TestValueClass()
    top_face_after_rolling_dice()

Submission status: Accepted

Solution code:
# coding: utf-8
# Here your code !
import sys
import collections
import unittest

def top_face_after_rolling_dice():
    try:
        faces    = [int(num) for num in input().rstrip().split()]
        rollings = input().rstrip()
    except:
        return __input_error()

    dice = CubicArbitraryValueDice(faces[0], faces[1], faces[2], faces[3], faces[4], faces[5])
    dice.put(dice.TOP, dice.SOUTH, dice.EAST, dice.WEST, dice.NORTH, dice.BOTTOM)
    
    for direction in rollings:
        dice.roll(direction)

    print(dice.faces[dice.direction[dice.TOP]])

class CubicArbitraryValueDice():
    TOP    = "top"
    BOTTOM = "bottom"
    EAST   = "E"
    WEST   = "W"
    SOUTH  = "S"
    NORTH  = "N"
    OPOSITE_DIRECTION_PAIRS = ( (EAST, WEST), (SOUTH, NORTH) )
    
    #??¢???index??§???????????????????????????
    def __init__(self, n_f0, n_f1, n_f2, n_f3, n_f4, n_f5):
        self.faces = [n_f0, n_f1, n_f2, n_f3, n_f4, n_f5]

    #???????????¢???index?????¢??£??????
    def put(self, dir_f0, dir_f1, dir_f2, dir_f3, dir_f4, dir_f5):  #?????°????????£?????????
        self.direction = { dir_fi : i for i,dir_fi in enumerate([dir_f0, dir_f1, dir_f2, dir_f3, dir_f4, dir_f5]) }

    #??¢???index????????´
    def roll(self, direction) : #dirction: (EAST, WEST, SOUTH, NORTH) ??????????????????
        for pair in self.OPOSITE_DIRECTION_PAIRS :
            if direction in pair :
                oposite = pair[0] if (pair[1] == direction) else pair[1]
        
        current = {}
        for direct in (self.TOP, self.BOTTOM, direction, oposite):
            current.update({direct : self.direction[direct]})

        #            direction to bottom,       bottom to oposite,      oposite to top,     top to direction 
        for pair in ((direction, self.BOTTOM), (self.BOTTOM, oposite), (oposite, self.TOP), (self.TOP, direction)):
            self.direction[pair[1]] = current[pair[0]]

def __input_error():
    print("input error")
    return -1
'''
class __TestValueClass(unittest.TestCase):
    def testEqual(self, func, tuples, eff_digit = math.nan, print_success = False):
        self.testFunction(self.assertEqual,func,tuples,eff_digit,print_success)
    
    def testFunction(self,assertfunc,func,tuples,eff_digit,print_success):
        #tuples[index] = ([*arguments of func], compared value)
        pass

        for item in tuples:
            try:
                if isinstance(item[0], collections.Iterable):
#                    value = func(*item[0])
                else:
                    value = func(item[0])
                
                if math.isnan(eff_digit) :
#                    assertfunc(value,item[1])
                else :
#                    format_str = "{0:."+str(eff_digit)+"g}"
#                    assertfunc(format_str.format(value),format_str.format(item[1]))
                    
            except Exception as msg:
                swidth = 15
                print("="*50)
                print("-- Assertion Error in '" + func.__name__ + "' --")
                info = []
                info.append(["arguments"     , item[0]    ])
                info.append(["compared value", item[1]    ])
                info.append(["message"       , "\n" + msg ])
                for state in info :
                    print(state[0].ljust(swidth) + ":", state[1])
                sys.exit()

        if print_success :
            print(func.__name__,": succeeded")
'''
#test
if __name__ == "__main__" :
#    test = __TestValueClass()
    top_face_after_rolling_dice()