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:
from typing import List


class Dice:

    def __init__(self, surface: List[int]):
        self.surface = surface

    def get_upper_sursurface(self) -> int:
        return self.surface[0]

    def invoke_method(self, mkey: str) -> None:
        if mkey == 'S':
            self.S()
            return None
        if mkey == 'N':
            self.N()
            return None
        if mkey == 'E':
            self.E()
            return None
        if mkey == 'W':
            self.W()
            return None
        raise ValueError(f'This method does not exist. : {mkey}')

    def S(self) -> None:
        tmp = [i for i in self.surface]
        self.surface[0] = tmp[4]
        self.surface[1] = tmp[0]
        self.surface[2] = tmp[2]
        self.surface[3] = tmp[3]
        self.surface[4] = tmp[5]
        self.surface[5] = tmp[1]

    def N(self) -> None:
        tmp = [i for i in self.surface]
        self.surface[0] = tmp[1]
        self.surface[1] = tmp[5]
        self.surface[2] = tmp[2]
        self.surface[3] = tmp[3]
        self.surface[4] = tmp[0]
        self.surface[5] = tmp[4]

    def E(self) -> None:
        tmp = [i for i in self.surface]
        self.surface[0] = tmp[3]
        self.surface[1] = tmp[1]
        self.surface[2] = tmp[0]
        self.surface[3] = tmp[5]
        self.surface[4] = tmp[4]
        self.surface[5] = tmp[2]

    def W(self) -> None:
        tmp = [i for i in self.surface]
        self.surface[0] = tmp[2]
        self.surface[1] = tmp[1]
        self.surface[2] = tmp[5]
        self.surface[3] = tmp[0]
        self.surface[4] = tmp[4]
        self.surface[5] = tmp[3]


# 提出用
data = [int(i) for i in input().split()]
order = list(input())

# # 動作確認用
# data = [int(i) for i in '1 2 4 8 16 32'.split()]
# order = list('EESWN')

dice = Dice(data)
for o in order:
    dice.invoke_method(o)
print(dice.get_upper_sursurface())

Submission status: Accepted

Solution code:
from typing import List


class Dice:

    def __init__(self, s: List[int]):
        self.s = s

    def get_s(self) -> int:
        return self.s[0]

    def invoke_method(self, mkey: str) -> None:
        if mkey == 'S':
            self.S()
            return None
        if mkey == 'N':
            self.N()
            return None
        if mkey == 'E':
            self.E()
            return None
        if mkey == 'W':
            self.W()
            return None
        raise ValueError(f'This method does not exist. : {mkey}')

    def set_s(self, s0, s1, s2, s3, s4, s5) -> None:
        self.s[0] = s0
        self.s[1] = s1
        self.s[2] = s2
        self.s[3] = s3
        self.s[4] = s4
        self.s[5] = s5

    def S(self) -> None:
        self.set_s(self.s[4], self.s[0], self.s[2], self.s[3], self.s[5],
                   self.s[1])

    def N(self) -> None:
        self.set_s(self.s[1], self.s[5], self.s[2], self.s[3], self.s[0],
                   self.s[4])

    def E(self) -> None:
        self.set_s(self.s[3], self.s[1], self.s[0], self.s[5], self.s[4],
                   self.s[2])

    def W(self) -> None:
        self.set_s(self.s[2], self.s[1], self.s[5], self.s[0], self.s[4],
                   self.s[3])


# 提出用
data = [int(i) for i in input().split()]
order = list(input())

# # 動作確認用
# data = [int(i) for i in '1 2 4 8 16 32'.split()]
# order = list('SE')

dice = Dice(data)
for o in order:
    dice.invoke_method(o)
print(dice.get_s())

Submission status: Accepted

Solution code:
class Dice:
	def __init__(self, ls):
		self.ls = ls
		self.now = 0
	
	def roll(self, direction):
		if direction == 'E': pat = [5, 2, 0, 3]
		elif direction == 'N': pat = [5, 4, 0, 1]
		elif direction == 'W': pat = [5, 3, 0, 2]
		elif direction == 'S': pat = [5, 1, 0, 4]

		tmp = self.ls[pat[0]]
		for i in range(4):
			try:
				self.ls[pat[i]] = self.ls[pat[i+1]]
			except(IndexError):
				pass
		self.ls[pat[-1]] = tmp
		
	def top(self):
		return self.ls[self.now]

dice = Dice(list(input().rstrip().split()))
for cmd in list(input().rstrip()):
	dice.roll(cmd)
print(dice.top())

Submission status: Accepted

Solution code:
#!/usr/bin/env python

class Dice:
    def __init__(self, top, s, e, w, n, bottom):
        self.top    = top
        self.s      = s
        self.e      = e
        self.w      = w
        self.n      = n
        self.bottom = bottom

    def rotate(self, dist):
        if dist == 'N':
            self.top, self.s, self.n, self.bottom = self.s, self.bottom, self.top, self.n 
        elif dist == 'S':
            self.s, self.bottom, self.top, self.n = self.top, self.s, self.n, self.bottom 
        elif dist == 'E':
            self.top, self.e, self.w, self.bottom = self.w, self.top, self.bottom, self.e 
        elif dist == 'W':
            self.w, self.top, self.bottom, self.e = self.top, self.e, self.w, self.bottom 

if __name__ == '__main__':
    num = map(int, raw_input().split())
    dice = Dice(*num)

    for c in raw_input():
        dice.rotate(c)
    print dice.top

Submission status: Accepted

Solution code:
#!/usr/bin/env python

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

faces = [1, 2, 3, 4, 5, 6]


def dice(command):

    if command == "N":
        faces[0], faces[1], faces[4], faces[5] = faces[1], faces[5], faces[0], faces[4]

    elif command == "S":
        faces[0], faces[1], faces[4], faces[5] = faces[4], faces[0], faces[5], faces[1]

    elif command == "E":
        faces[0], faces[2], faces[3], faces[5] = faces[3], faces[0], faces[5], faces[2]

    else:  # command W
        faces[0], faces[2], faces[3], faces[5] = faces[2], faces[5], faces[0], faces[3]


for c in command:
    dice(c)

print(label[faces[0] - 1])

Submission status: Accepted

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

Submission status: Accepted

Solution code:
class Dice:
    def __init__(self, eyes):
        self._eyes = eyes

    @property
    def eye(self):
        return self._eyes[1]

    def roll(self, direction):
        if direction == 'N':
            old = self._eyes
            new = ['dummy'] * 7
            new[1] = old[2]
            new[2] = old[6]
            new[3] = old[3]
            new[4] = old[4]
            new[5] = old[1]
            new[6] = old[5]
            self._eyes = new
        elif direction == 'S':
            old = self._eyes
            new = ['dummy'] * 7
            new[1] = old[5]
            new[2] = old[1]
            new[3] = old[3]
            new[4] = old[4]
            new[5] = old[6]
            new[6] = old[2]
            self._eyes = new
        elif direction == 'W':
            old = self._eyes
            new = ['dummy'] * 7
            new[1] = old[3]
            new[2] = old[2]
            new[3] = old[6]
            new[4] = old[1]
            new[5] = old[5]
            new[6] = old[4]
            self._eyes = new
        elif direction == 'E':
            old = self._eyes
            new = ['dummy'] * 7
            new[1] = old[4]
            new[2] = old[2]
            new[3] = old[1]
            new[4] = old[6]
            new[5] = old[5]
            new[6] = old[3]
            self._eyes = new
        else:
            raise ValueError('NEWS箱推し')


eyes = ['dummy'] + input().split()
dice = Dice(eyes)

direction_text = input()
for d in direction_text:
    dice.roll(d)

print(dice.eye)

Submission status: Accepted

Solution code:
class Dice:
    def __init__(self, eyes):
        self._eyes = ['dummy'] + eyes

    @property
    def eye(self):
        return self._eyes[1]

    def roll(self, direction):
        if direction == 'N':
            old = self._eyes
            new = ['dummy'] * 7
            new[1] = old[2]
            new[2] = old[6]
            new[3] = old[3]
            new[4] = old[4]
            new[5] = old[1]
            new[6] = old[5]
            self._eyes = new
        elif direction == 'S':
            old = self._eyes
            new = ['dummy'] * 7
            new[1] = old[5]
            new[2] = old[1]
            new[3] = old[3]
            new[4] = old[4]
            new[5] = old[6]
            new[6] = old[2]
            self._eyes = new
        elif direction == 'W':
            old = self._eyes
            new = ['dummy'] * 7
            new[1] = old[3]
            new[2] = old[2]
            new[3] = old[6]
            new[4] = old[1]
            new[5] = old[5]
            new[6] = old[4]
            self._eyes = new
        elif direction == 'E':
            old = self._eyes
            new = ['dummy'] * 7
            new[1] = old[4]
            new[2] = old[2]
            new[3] = old[1]
            new[4] = old[6]
            new[5] = old[5]
            new[6] = old[3]
            self._eyes = new
        else:
            raise ValueError('NEWS箱推し')


eyes = input().split()
dice = Dice(eyes)

direction_text = input()
for d in direction_text:
    dice.roll(d)

print(dice.eye)

Submission status: Accepted

Solution code:
import copy


class Dice:
    def __init__(self, eyes):
        self._top = eyes[0]
        self._front = eyes[1]
        self._right = eyes[2]
        self._left = eyes[3]
        self._back = eyes[4]
        self._bottom = eyes[5]

    @property
    def eye(self):
        return self._top

    def roll(self, direction):
        old = copy.copy(self)
        if direction == 'N':
            self._top = old._front
            self._front = old._bottom
            self._back = old._top
            self._bottom = old._back
        elif direction == 'S':
            self._top = old._back
            self._front = old._top
            self._back = old._bottom
            self._bottom = old._front
        elif direction == 'W':
            self._top = old._right
            self._right = old._bottom
            self._left = old._top
            self._bottom = old._left
        elif direction == 'E':
            self._top = old._left
            self._right = old._top
            self._left = old._bottom
            self._bottom = old._right
        else:
            raise ValueError('NEWS箱推し')


eyes = input().split()
dice = Dice(eyes)

direction_text = input()
for d in direction_text:
    dice.roll(d)

print(dice.eye)

Submission status: Accepted

Solution code:
class dice:
    value = [0] * 6
    def __init__(self, list):
        self.value = list

    def dice_roll(self,dir):
        if dir == "S":
            prev = self.value
            self.value = [prev[4],prev[0],prev[2],prev[3],prev[5],prev[1]]
        elif dir == "N":
            prev = self.value
            self.value = [prev[1],prev[5],prev[2],prev[3],prev[0],prev[4]]
        elif dir == "W":
            prev = self.value
            self.value = [prev[2],prev[1],prev[5],prev[0],prev[4],prev[3]]
        elif dir == "E":
            prev = self.value
            self.value = [prev[3],prev[1],prev[0],prev[5],prev[4],prev[2]]

mydice = dice(list(map(int, input().split())))
x = str(input())
for i in x:
    mydice.dice_roll(i)
print(mydice.value[0])

Submission status: Accepted

Solution code:
class Dice:
    def __init__(self, eyes):
        self._eyes = ['dummy'] + eyes

    @property
    def eye(self):
        return self._eyes[1]

    def roll(self, direction):
        old = self._eyes
        new = ['dummy'] * 7
        if direction == 'N':
            new[1] = old[2]
            new[2] = old[6]
            new[3] = old[3]
            new[4] = old[4]
            new[5] = old[1]
            new[6] = old[5]
        elif direction == 'S':
            new[1] = old[5]
            new[2] = old[1]
            new[3] = old[3]
            new[4] = old[4]
            new[5] = old[6]
            new[6] = old[2]
        elif direction == 'W':
            new[1] = old[3]
            new[2] = old[2]
            new[3] = old[6]
            new[4] = old[1]
            new[5] = old[5]
            new[6] = old[4]
        elif direction == 'E':
            new[1] = old[4]
            new[2] = old[2]
            new[3] = old[1]
            new[4] = old[6]
            new[5] = old[5]
            new[6] = old[3]
        else:
            raise ValueError('NEWS箱推し')
        self._eyes = new


eyes = input().split()
dice = Dice(eyes)

direction_text = input()
for d in direction_text:
    dice.roll(d)

print(dice.eye)

Submission status: Accepted

Solution code:
class Dice:
    def __init__(self, eyes):
        self._eyes = ['dummy'] + eyes

    @property
    def eye(self):
        return self._eyes[1]

    def roll(self, direction):
        a = self._eyes
        if direction == 'N':
            self._eyes = ['dummy', a[2], a[6], a[3], a[4], a[1], a[5]]
        elif direction == 'S':
            self._eyes = ['dummy', a[5], a[1], a[3], a[4], a[6], a[2]]
        elif direction == 'W':
            self._eyes = ['dummy', a[3], a[2], a[6], a[1], a[5], a[4]]
        elif direction == 'E':
            self._eyes = ['dummy', a[4], a[2], a[1], a[6], a[5], a[3]]
        else:
            raise ValueError('NEWS箱推し')


eyes = input().split()
dice = Dice(eyes)

direction_text = input()
for d in direction_text:
    dice.roll(d)

print(dice.eye)

Submission status: Accepted

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

    def rotate(self, dic):
        if dic == "N":
            tmp = self.u
            self.u = self.s
            self.s = self.d
            self.d = self.n
            self.n = tmp
        elif dic == "E":
            tmp = self.u
            self.u = self.w
            self.w = self.d
            self.d = self.e
            self.e = tmp
        elif dic == "W":
            tmp = self.u
            self.u = self.e
            self.e = self.d
            self.d = self.w
            self.w = tmp
        else:
            tmp = self.u
            self.u = self.n
            self.n = self.d
            self.d = self.s
            self.s = tmp


def main():
    u, s, e, w, n, d = map(int, input().split())
    O = input()

    cube = Cube(u, s, e, w, n, d)
    for i in range(len(O)):
        cube.rotate(O[i])
    print(cube.u)


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
#!/usr/bin/env python3
# coding: utf-8

class dice ():
    def __init__(self, data):
        self.up = data[0]
        self.down = data[5]
        self.left = data[3]
        self.right =data[2]
        self.front = data[1]
        self.back = data[4]

    def turn_s(self):
        tmp = self.up
        self.up = self.back
        self.back = self.down
        self.down = self.front
        self.front = tmp

    def turn_n(self):
        tmp = self.up
        self.up = self.front
        self.front = self.down
        self.down = self.back
        self.back = tmp

    def turn_w(self):
        tmp = self.up
        self.up = self.right
        self.right = self.down
        self.down = self.left
        self.left = tmp

    def turn_e(self):
        tmp = self.up
        self.up = self.left
        self.left = self.down
        self.down = self.right
        self.right = tmp

    def turn(self, rotate="N"):
        if (rotate == "N"):
            self.turn_n()
        elif (rotate == "E"):
            self.turn_e()
        elif (rotate == "W"):
            self.turn_w()
        elif (rotate == "S"):
            self.turn_s()
        else:
            none

    def get_up(self):
        return self.up



dicedata = input().split()
orderdata = input()

newdice = dice(dicedata)

[newdice.turn(orderdata[idx]) for idx in range(0, len(orderdata))]

print(newdice.get_up())

Submission status: Accepted

Solution code:
#!/usr/bin/env python3
# coding: utf-8

class Dice() :

    mask = {'N':(1,5,2,3,0,4), 'E':(3,1,0,5,4,2),
            'W':(2,1,5,0,4,3), 'S':(4,0,2,3,5,1)}

    def __init__(self, data):
        self.label = data

    def move(self, data):
        self.label = [self.label[idx] for idx in self.mask[data]]

    def get_up(self):
        return self.label[0]

dicedata = input().split()
orderdata = input()

newdice = Dice(dicedata)

[newdice.move(orderdata[idx]) for idx in range(0, len(orderdata))]

print(newdice.get_up())

Submission status: Accepted

Solution code:
def roll(l, command):
    '''
    return rolled list

    l : string list
    command: string
    '''
    res = []
    i = -1
    if command =='N':
        res = [l[i+2], l[i+6], l[i+3], l[i+4], l[i+1], l[i+5]]
    if command =='S':
        res = [l[i+5], l[i+1], l[i+3], l[i+4], l[i+6], l[i+2]]
    if command =='E':
        res = [l[i+4], l[i+2], l[i+1], l[i+6], l[i+5], l[i+3]]
    if command =='W':
        res = [l[i+3], l[i+2], l[i+6], l[i+1], l[i+5], l[i+4]]

    return res

faces = input().split()
commands = list(input())

for command in commands:
    faces = roll(faces, command)

print(faces[0])

Submission status: Accepted

Solution code:
class dice:
    def roll(self,direction):
        if direction=="N":
            self.face=[self.face[1],self.face[5],self.face[2],self.face[3],self.face[0],self.face[4]]
        if direction=="E":
            self.face=[self.face[3],self.face[1],self.face[0],self.face[5],self.face[4],self.face[2]]
        if direction=="W":
            self.face=[self.face[2],self.face[1],self.face[5],self.face[0],self.face[4],self.face[3]]
        if direction=="S":
            self.face=[self.face[4],self.face[0],self.face[2],self.face[3],self.face[5],self.face[1]]
dice1=dice()
dice1.face=list(map(int,input().split()))
for i in input():
    dice1.roll(i)
print(dice1.face[0])

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:
houkou={'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)}
saikoro=input().split()
for i in input():
  saikoro=[saikoro[j]for j in houkou[i]]
  #print(saikoro)
print(saikoro[0])

Submission status: Accepted

Solution code:
class Dice(object):
    def __init__(self, top, south, east, west, north, bottom):
        self.top = top
        self.south = south
        self.east = east
        self.west = west
        self.north = north
        self.bottom = bottom
    def rollN(self):
        prevN = self.north
        prevB = self.bottom
        prevS = self.south
        self.north = self.top
        self.bottom = prevN
        self.south = prevB
        self.top = prevS
    def rollS(self):
        prevS = self.south
        prevB = self.bottom
        prevN = self.north
        self.south = self.top
        self.bottom = prevS
        self.north = prevB
        self.top = prevN
    def rollE(self):
        prevE = self.east
        prevB = self.bottom
        prevW = self.west
        self.east = self.top
        self.bottom = prevE
        self.west = prevB
        self.top = prevW
    def rollW(self):
        prevW = self.west
        prevB = self.bottom
        prevE = self.east
        self.west = self.top
        self.bottom = prevW
        self.east = prevB
        self.top = prevE

diceInit = [int(n) for n in raw_input().split()][:6:]
instruction = raw_input()

diceI = Dice(diceInit[0], diceInit[1], diceInit[2], diceInit[3], diceInit[4], diceInit[5])

for item in instruction:
    if item == 'N':
        diceI.rollN()
    elif item == 'E':
        diceI.rollE()
    elif item == 'W':
        diceI.rollW()
    elif item == 'S':
        diceI.rollS()

print diceI.top

Submission status: Accepted

Solution code:
class Dice(object):
    def __init__(self, s1, s2, s3, s4, s5, s6):
        self.s1 = s1
        self.s2 = s2
        self.s3 = s3
        self.s4 = s4
        self.s5 = s5
        self.s6 = s6
    def east(self):
        prev_s6 = self.s6
        self.s6 = self.s3
        self.s3 = self.s1
        self.s1 = self.s4
        self.s4 = prev_s6
    def west(self):
        prev_s6 = self.s6
        self.s6 = self.s4
        self.s4 = self.s1
        self.s1 = self.s3
        self.s3 = prev_s6
    def north(self):
        prev_s6 = self.s6
        self.s6 = self.s5
        self.s5 = self.s1
        self.s1 = self.s2
        self.s2 = prev_s6
    def south(self):
        prev_s6 = self.s6
        self.s6 = self.s2
        self.s2 = self.s1
        self.s1 = self.s5
        self.s5 = prev_s6
    def top(self):
        return self.s1

s1, s2, s3, s4, s5, s6 = map(int, input().split())
dice = Dice(s1, s2, s3, s4, s5, s6)
order = input()
for c in order:
    if c == 'N':
        dice.north()
    elif c == 'W':
        dice.west()
    elif c == 'E':
        dice.east()
    elif c == 'S':
        dice.south()
print(dice.top())

Submission status: Accepted

Solution code:
def north(d):
    return [d[1], d[5], d[2], d[3], d[0], d[4]]

def east(d):
    return [d[3], d[1], d[0], d[5], d[4], d[2]]

def south(d):
    return [d[4], d[0], d[2], d[3], d[5], d[1]]

def west(d):
    return [d[2], d[1], d[5], d[0], d[4], d[3]]

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

for d in directions:
    if d == "N":
        numbers = north(numbers)
    elif d == "E":
        numbers = east(numbers)
    elif d == "S":
        numbers = south(numbers)
    elif d == "W":
        numbers = west(numbers)

print(numbers[0])

Submission status: Accepted

Solution code:
def rot(dice, I):
  #USEWND
  #NEWSUD
  a = dice[:]
  if I=='N': x=[0,4,5,1,0]
  elif I=='E': x=[0,2,5,3,0]
  elif I=='W': x=[0,3,5,2,0]
  elif I=='S': x=[0,1,5,4,0]
  for i in [0,1,2,3]: a[x[i+1]]=dice[x[i]]
  return a

dice = map(int,raw_input().split())
for c in raw_input(): dice = rot(dice,c)
print dice[0]

Submission status: Accepted

Solution code:
def get_dice(pips):
    return [[0, pips[4], 0, 0], 
                   [pips[3], pips[0], pips[2], pips[5]], 
                   [0, pips[1], 0, 0]]

def move_e(dice):
    dice[1] = dice[1][3:] + dice[1][:3]
    return dice

def move_n(dice):
    return [[0,          dice[1][1], 0, 0],
            [dice[1][0], dice[2][1], dice[1][2], dice[0][1]],
            [0,                 dice[1][3], 0, 0]]

def move_s(dice):
    return [[0,          dice[1][3], 0, 0],
            [dice[1][0], dice[0][1], dice[1][2], dice[2][1]],
            [0,                 dice[1][1], 0, 0]]

def move_w(dice):
    dice[1] = dice[1][1:] + dice[1][:1]
    return dice

func = {'E':move_e,'N':move_n,'S':move_s,'W':move_w}

dice = get_dice(list(map(int, input().split())))

for c in input():
    dice = func[c](dice)

print(dice[1][1])

Submission status: Accepted

Solution code:
mask = {'N':(1, 5, 2, 3, 0, 4), 'E':(3, 1, 0, 5, 4, 2), 'S':(4, 0, 2, 3, 5, 1), 'W':(2, 1, 5, 0, 4,3)}

dice = input().split()

for c in input():
    dice = [dice[i] for i in mask[c]]

print(dice[0])

Submission status: Accepted

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

    def getTop(self):
        return self.data[0]

dice = Dice(input().split())
cmd = input()
for i in range(len(cmd)):
    dice.move(cmd[i])
print(dice.getTop())

Submission status: Accepted

Solution code:
class Dice:
    def __init__(self, data):
        self.data = data

    def move(self, direction):
        if direction == 'E':
            self.data[0],self.data[3], self.data[5], self.data[2] = \
                self.data[3],self.data[5], self.data[2], self.data[0] 
        elif direction == 'N':
            self.data[0],self.data[1], self.data[5], self.data[4] = \
                self.data[1],self.data[5], self.data[4], self.data[0]
        elif direction == 'S':
            self.data[0],self.data[1], self.data[5], self.data[4] = \
                self.data[4],self.data[0], self.data[1], self.data[5]
        elif direction == 'W':
            self.data[0],self.data[2], self.data[5], self.data[3] = \
                self.data[2],self.data[5], self.data[3], self.data[0]

    def getTop(self):
        return self.data[0]

dice = Dice(input().split())
cmd = input()
for i in range(len(cmd)):
    dice.move(cmd[i])
print(dice.getTop())

Submission status: Accepted

Solution code:
class Dice:
    def __init__(self, data):
        self.data = data

    def move(self, direction):
        if direction == 'E':
            self.data[0],self.data[3],self.data[5],self.data[2] = \
                    self.data[3],self.data[5],self.data[2],self.data[0]
        elif direction == 'N':
            self.data[0],self.data[4],self.data[5],self.data[1] = \
                    self.data[1],self.data[0],self.data[4],self.data[5]
        elif direction == 'S':
            self.data[0],self.data[1],self.data[5],self.data[4] = \
                    self.data[4],self.data[0],self.data[1],self.data[5]
        elif direction == 'W':
             self.data[0],self.data[2],self.data[5],self.data[3] = \
                    self.data[2],self.data[5],self.data[3],self.data[0]


    def getTop(self):
        return self.data[0]

dice = Dice(input().split())
cmd = input()
for i in range(len(cmd)):
    dice.move(cmd[i])

print(dice.getTop())

Submission status: Accepted

Solution code:
class Dice:
    def __init__ (self,data):
        self.data = data

    def move(self,direction):
        if direction == 'E':
            self.data[0],self.data[3],self.data[5],self.data[2] = \
                    self.data[3],self.data[5],self.data[2],self.data[0]
        elif direction == 'N':
            self.data[0],self.data[4],self.data[5],self.data[1] = \
                    self.data[1],self.data[0],self.data[4],self.data[5]
        elif direction == 'S':
            self.data[0],self.data[1],self.data[5],self.data[4] = \
                    self.data[4],self.data[0],self.data[1],self.data[5]
        elif direction == 'W':
            self.data[0],self.data[2],self.data[5],self.data[3] = \
                    self.data[2],self.data[5],self.data[3],self.data[0]

    def getTop(self):
        return self.data[0]

dice = Dice(input().split())
cmd = input()
for i in range(len(cmd)):
    dice.move(cmd[i])
print(dice.getTop())

Submission status: Accepted

Solution code:
import sys

dice = [int(i) for i in sys.stdin.readline().split()]
command = sys.stdin.readline().strip()
for c in command:
    if c == "N":
        dice = (dice[1], dice[5], dice[2], dice[3], dice[0], dice[4])
    elif c == "S":
        dice = (dice[4], dice[0], dice[2], dice[3], dice[5], dice[1])
    elif c == "W":
        dice = (dice[2], dice[1], dice[5], dice[0], dice[4], dice[3])
    elif c == "E":
        dice = (dice[3], dice[1], dice[0], dice[5], dice[4], dice[2])
print(dice[0])

Submission status: Accepted

Solution code:
import sys

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

    def roll_north(self):
        self.__dice = (self.__dice[1], self.__dice[5], self.__dice[2],
                       self.__dice[3], self.__dice[0], self.__dice[4])

    def roll_south(self):
        self.__dice = (self.__dice[4], self.__dice[0], self.__dice[2],
                       self.__dice[3], self.__dice[5], self.__dice[1])

    def roll_west(self):
        self.__dice = (self.__dice[2], self.__dice[1], self.__dice[5],
                       self.__dice[0], self.__dice[4], self.__dice[3])

    def roll_east(self):
        self.__dice = (self.__dice[3], self.__dice[1], self.__dice[0],
                       self.__dice[5], self.__dice[4], self.__dice[2])

    def number(self, face_id):
        return self.__dice[face_id - 1]


dice = Dice([int(i) for i in sys.stdin.readline().split()])
command = sys.stdin.readline().strip()
for c in command:
    if c == "N":
        dice.roll_north()
    elif c == "S":
        dice.roll_south()
    elif c == "W":
        dice.roll_west()
    elif c == "E":
        dice.roll_east()
print(dice.number(1))

Submission status: Accepted

Solution code:
class Dice:
    def __init__(self,ls):
        self.a = ls[0]
        self.b = ls[1]
        self.c = ls[2]
        self.d = ls[3]
        self.e = ls[4]
        self.f = ls[5]
    
    def E(self):
        self.a, self.c, self.f, self.d = self.d, self.a, self.c, self.f
    def W(self):
        self.a, self.c, self.f, self.d = self.c, self.f, self.d, self.a
    def S(self):
        self.a, self.b, self.f, self.e = self.e, self.a, self.b, self.f
    def N(self):
        self.a, self.b, self.f, self.e = self.b, self.f, self.e, self.a
    
ls = map(int,raw_input().split())
orders = raw_input()
dice = Dice(ls)
for w in orders:
    if w == 'E': dice.E()
    elif w == 'W': dice.W()
    elif w == 'S': dice.S()
    elif w == 'N': dice.N()
print dice.a