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:
# 1: top, 2: front, 3: right,
# 4: left, 5: back, 6: bottom

class Dice:
    def __init__(self, nums):
        self.top, self.front, self.right, self.left, self.back, self.bottom = nums

    def roll(self, direction):
        if direction == 'E':
            self.top, self.right, self.left, self.bottom = self.left, self.top, self.bottom, self.right
            return

        if direction == 'N':
            self.top, self.front, self.back, self.bottom = self.front, self.bottom, self.top, self.back
            return

        if direction == 'S':
            self.top, self.front, self.back, self.bottom = self.back, self.top, self.bottom, self.front
            return

        if direction == 'W':
            self.top, self.right, self.left, self.bottom = self.right, self.bottom, self.top, self.left
            return

    def get_top(self):
        return self.top

if __name__ == '__main__':
    nums = [int(i) for i in input().split()]
    directions = input()

    d = Dice(nums)
    for ch in directions:
        d.roll(ch)

    print(d.get_top())

Submission status: Accepted

Solution code:
# 1: top, 2: front, 3: right,
# 4: left, 5: back, 6: bottom

class Dice:
    def __init__(self, nums):
        self.top, self.front, self.right, self.left, self.back, self.bottom = nums

    def roll(self, direction):
        if direction == 'E':
            self.top, self.right, self.left, self.bottom = self.left, self.top, self.bottom, self.right
            return

        if direction == 'N':
            self.top, self.front, self.back, self.bottom = self.front, self.bottom, self.top, self.back
            return

        if direction == 'S':
            self.top, self.front, self.back, self.bottom = self.back, self.top, self.bottom, self.front
            return

        if direction == 'W':
            self.top, self.right, self.left, self.bottom = self.right, self.bottom, self.top, self.left
            return

    def get_top(self):
        return self.top

if __name__ == '__main__':
    nums = [int(i) for i in input().split()]
    directions = input()

    d = Dice(nums)
    for i in range(len(directions)):
        d.roll(directions[i])

    print(d.get_top())

Submission status: Accepted

Solution code:
#coding:utf-8
#1_11_A 2015.4.17
class Dice:
    def __init__(self,ary):
        self.top = ary[0]
        self.south = ary[1]
        self.east = ary[2]
        self.west = ary[3]
        self.north = ary[4]
        self.bottom = ary[5]

    def get_top(self):
        return self.top

    def roll_n(self):
        self.top , self.south , self.bottom , self.north = self.south , self.bottom , self.north , self.top

    def roll_s(self):
        self.top , self.north , self.bottom , self.south = self.north , self.bottom , self.south , self.top

    def roll_e(self):
        self.top , self.west , self.bottom , self.east = self.west , self.bottom , self.east , self.top

    def roll_w(self):
        self.top , self.east , self.bottom , self.west = self.east , self.bottom , self.west , self.top

dice = Dice(input().split())
cmds = input()
for cmd in cmds:
    if cmd == 'N':
        dice.roll_n()
    elif cmd == 'S':
        dice.roll_s()
    elif cmd == 'E':
        dice.roll_e()
    elif cmd == 'W':
        dice.roll_w()

print(dice.get_top())

Submission status: Accepted

Solution code:
import sys
data=list(map(int,input().split()))
order=sys.stdin.readline()
char_list=list(order)
for i in char_list:
	
	if i=='N':
		k=data[0]
		m=data[4]
		data[0]=data[1]
		data[1]=data[5]
		data[4]=k
		data[5]=m
	elif i=='E':
		k=data[0]
		m=data[2]
		data[0]=data[3]
		data[2]=k
		data[3]=data[5]	
		data[5]=m
	elif i=='S':
		k=data[0]
		m=data[1]
		data[0]=data[4]
		data[1]=k
		data[4]=data[5]
		data[5]=m
	elif i=='W':
		k=data[0]
		m=data[3]
		data[0]=data[2]
		data[2]=data[5]
		data[3]=k
		data[5]=m
print(data[0])

Submission status: Accepted

Solution code:
import sys

class Dice(object):
	def __init__(self, data):
		self.dice=data
	def roll_n(self):
		self.dice=(self.dice[1],self.dice[5],self.dice[2],
					self.dice[3],self.dice[0],self.dice[4])
	def roll_e(self):
		self.dice=(self.dice[3],self.dice[1],self.dice[0],
					self.dice[5],self.dice[4],self.dice[2])
	def roll_w(self):
		self.dice=(self.dice[2],self.dice[1],self.dice[5],
					self.dice[0],self.dice[4],self.dice[3])				
	def roll_s(self):
		self.dice=(self.dice[4],self.dice[0],self.dice[2],
					self.dice[3],self.dice[5],self.dice[1])
	def get_top(self, id):
 		return self.dice[id-1]

data=Dice([int(i) for i in sys.stdin.readline().split()])
order=sys.stdin.readline().strip()
for i in order:
	if i=='N':
		data.roll_n()
	elif i=='E':
		data.roll_e()
	elif i=='S':
		data.roll_s()
	elif i=='W':
		data.roll_w()
print(data.get_top(1))

Submission status: Accepted

Solution code:
l=map(int,raw_input().split())
n=raw_input()
ans=chk=0


def rolling(word,dice):
    if word=='S':
        dice[0],dice[1],dice[5],dice[4]=dice[4],dice[0],dice[1],dice[5]
    elif word=='N':
        dice[0],dice[1],dice[5],dice[4]=dice[1],dice[5],dice[4],dice[0]
    elif word=='W':
        dice[0],dice[2],dice[5],dice[3]=dice[2],dice[5],dice[3],dice[0]
    else:
        dice[0],dice[2],dice[5],dice[3]=dice[3],dice[0],dice[2],dice[5]
    return dice

for i in n:
    l=rolling(i,l)
print l[0]

Submission status: Accepted

Solution code:
diceface = { "TOP":0,"FRONT":1,"RIGHT":2,"LEFT":3,"BACK":4,"BOTTOM":5 }

dice = [ int( i ) for i in raw_input( ).split( " " ) ]
roll = raw_input( )
for i in range( len(  roll ) ):
	if "E" == roll[i]:
		t = dice[ diceface["TOP"] ]
		dice[ diceface["TOP"] ] = dice[ diceface["LEFT"] ]
		dice[ diceface["LEFT"] ] = dice[ diceface["BOTTOM"] ]
		dice[ diceface["BOTTOM"] ] = dice[ diceface["RIGHT"] ]
		dice[ diceface["RIGHT"] ] = t
	elif "N" == roll[i]:
		t = dice[ diceface["TOP"] ]
		dice[ diceface["TOP"] ] = dice[ diceface["FRONT"] ]
		dice[ diceface["FRONT"] ] = dice[ diceface["BOTTOM"] ]
		dice[ diceface["BOTTOM"] ] = dice[ diceface["BACK"] ]
		dice[ diceface["BACK"] ] = t
	elif "S" == roll[i]:
		t = dice[ diceface["TOP"] ]
		dice[ diceface["TOP"] ] = dice[ diceface["BACK"] ]
		dice[ diceface["BACK"] ] = dice[ diceface["BOTTOM"] ]
		dice[ diceface["BOTTOM"] ] = dice[ diceface["FRONT"] ]
		dice[ diceface["FRONT"] ] = t
	elif "W" == roll[i]:
		t = dice[ diceface["TOP"] ]
		dice[ diceface["TOP"] ] = dice[ diceface["RIGHT"] ]
		dice[ diceface["RIGHT"] ] = dice[ diceface["BOTTOM"] ]
		dice[ diceface["BOTTOM"] ] = dice[ diceface["LEFT"] ]
		dice[ diceface["LEFT"] ] = t	

print( dice[ diceface["TOP"] ] )

Submission status: Accepted

Solution code:
diceface = { "TOP":0,"FRONT":1,"RIGHT":2,"LEFT":3,"BACK":4,"BOTTOM":5 }

dice = [ int( i ) for i in input( ).split( " " ) ]
roll = input( )
for i in range( len(  roll ) ):
	if "E" == roll[i]:
		t = dice[ diceface["TOP"] ]
		dice[ diceface["TOP"] ] = dice[ diceface["LEFT"] ]
		dice[ diceface["LEFT"] ] = dice[ diceface["BOTTOM"] ]
		dice[ diceface["BOTTOM"] ] = dice[ diceface["RIGHT"] ]
		dice[ diceface["RIGHT"] ] = t
	elif "N" == roll[i]:
		t = dice[ diceface["TOP"] ]
		dice[ diceface["TOP"] ] = dice[ diceface["FRONT"] ]
		dice[ diceface["FRONT"] ] = dice[ diceface["BOTTOM"] ]
		dice[ diceface["BOTTOM"] ] = dice[ diceface["BACK"] ]
		dice[ diceface["BACK"] ] = t
	elif "S" == roll[i]:
		t = dice[ diceface["TOP"] ]
		dice[ diceface["TOP"] ] = dice[ diceface["BACK"] ]
		dice[ diceface["BACK"] ] = dice[ diceface["BOTTOM"] ]
		dice[ diceface["BOTTOM"] ] = dice[ diceface["FRONT"] ]
		dice[ diceface["FRONT"] ] = t
	elif "W" == roll[i]:
		t = dice[ diceface["TOP"] ]
		dice[ diceface["TOP"] ] = dice[ diceface["RIGHT"] ]
		dice[ diceface["RIGHT"] ] = dice[ diceface["BOTTOM"] ]
		dice[ diceface["BOTTOM"] ] = dice[ diceface["LEFT"] ]
		dice[ diceface["LEFT"] ] = t	

print( dice[ diceface["TOP"] ] )

Submission status: Accepted

Solution code:
diceface = { "TOP":0,"FRONT":1,"RIGHT":2,"LEFT":3,"BACK":4,"BOTTOM":5 }

dice = [ int( i ) for i in raw_input( ).split( " " ) ]
roll = raw_input( )
for i in roll:
	if "E" == i:
		t = dice[ diceface["TOP"] ]
		dice[ diceface["TOP"] ] = dice[ diceface["LEFT"] ]
		dice[ diceface["LEFT"] ] = dice[ diceface["BOTTOM"] ]
		dice[ diceface["BOTTOM"] ] = dice[ diceface["RIGHT"] ]
		dice[ diceface["RIGHT"] ] = t
	elif "N" == i:
		t = dice[ diceface["TOP"] ]
		dice[ diceface["TOP"] ] = dice[ diceface["FRONT"] ]
		dice[ diceface["FRONT"] ] = dice[ diceface["BOTTOM"] ]
		dice[ diceface["BOTTOM"] ] = dice[ diceface["BACK"] ]
		dice[ diceface["BACK"] ] = t
	elif "S" == i:
		t = dice[ diceface["TOP"] ]
		dice[ diceface["TOP"] ] = dice[ diceface["BACK"] ]
		dice[ diceface["BACK"] ] = dice[ diceface["BOTTOM"] ]
		dice[ diceface["BOTTOM"] ] = dice[ diceface["FRONT"] ]
		dice[ diceface["FRONT"] ] = t
	elif "W" == i:
		t = dice[ diceface["TOP"] ]
		dice[ diceface["TOP"] ] = dice[ diceface["RIGHT"] ]
		dice[ diceface["RIGHT"] ] = dice[ diceface["BOTTOM"] ]
		dice[ diceface["BOTTOM"] ] = dice[ diceface["LEFT"] ]
		dice[ diceface["LEFT"] ] = t	

print( dice[ diceface["TOP"] ] )

Submission status: Accepted

Solution code:
class Dice:
    def __init__(self, top, front, right, left, back, bottom):
        self.top,   self.bottom = top, bottom
        self.right, self.left   = right, left
        self.front, self.back   = front, back

    def rot(self, d):
        if   d == "N":
            self.top, self.back, self.bottom, self.front = self.front, self.top, self.back, self.bottom
        elif d == "S":
            self.top, self.back, self.bottom, self.front = self.back, self.bottom, self.front, self.top
        elif d == "E":
            self.top, self.right, self.bottom, self.left = self.left, self.top, self.right, self.bottom
        elif d == "W":
            self.top, self.right, self.bottom, self.left = self.right, self.bottom, self.left, self.top

ls = map(int, raw_input().split())
dice = Dice(ls[0], ls[1], ls[2], ls[3], ls[4], ls[5])
for d in raw_input():
    dice.rot(d)
print dice.top

Submission status: Accepted

Solution code:
# coding=utf-8


class Dice(object):

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

    def rotateS(self):
        s1, s2, s3, s4, s5, s6 = self.label
        self.label = [s5, s1, s3, s4, s6, s2]

    def rotateN(self):
        s1, s2, s3, s4, s5, s6 = self.label
        self.label = [s2, s6, s3, s4, s1, s5]

    def rotateE(self):
        s1, s2, s3, s4, s5, s6 = self.label
        self.label = [s4, s2, s1, s6, s5, s3]

    def rotateW(self):
        s1, s2, s3, s4, s5, s6 = self.label
        self.label = [s3, s2, s6, s1, s5, s4]

    def rotate(self, r):
        if r == 'S':
            self.rotateS()
        elif r == 'N':
            self.rotateN()
        elif r == 'E':
            self.rotateE()
        elif r == 'W':
            self.rotateW()
        else:
            print 'Cannot rotate into ' + r + 'direction.'

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


if __name__ == '__main__':
    d = Dice(map(int, raw_input().split()))
    rotations = raw_input()
    for r in rotations:
        d.rotate(r)
    print d.getTopLabel()

Submission status: Accepted

Solution code:
class Dice:

    def __init__(self, faces):
        self.faces = tuple(faces)

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

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

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

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

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


dice = Dice(list(map(int, input().split())))
commands = input()

for c in commands:
    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:
a = list(map(int, input().split()))
commands = input()
for command in commands:
    if command == 'N':
        a[0], a[1], a[5], a[4] = a[1], a[5], a[4], a[0]
    elif command == 'S':
        a[0], a[1], a[5], a[4] = a[4], a[0], a[1], a[5]
    elif command == 'W':
        a[0], a[3], a[5], a[2] = a[2], a[0], a[3], a[5]
    elif command == 'E':
        a[0], a[3], a[5], a[2] = a[3], a[5], a[2], a[0]
print(a[0])

Submission status: Accepted

Solution code:
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]}
d=map(int, raw_input().split())
nd=[0]*6
dir=raw_input()
for i in range(len(dir)):
    x=dir[i]
    for j in range(6):
        nd[j]=d[m[x][j]]
    d=list(nd)
print d[0]

Submission status: Accepted

Solution code:
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]}
d=map(int, raw_input().split())
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:
  def __init__(self, list = map(str, range(1, 7))):
    self.top = list[0]
    self.front = list[1]
    self.right = list[2]
    self.left = list[3]
    self.back = list[4]
    self.bottom = list[5]

  def print_all(self):
    print "top = " + self.top
    print "front = " + self.front
    print "right = " + self.right
    print "left = " + self.left
    print "back = " + self.back
    print "bottom = " + self.bottom

  def roll_N(self):
    temp = self.top
    self.top = self.front
    self.front = self.bottom
    self.bottom = self.back
    self.back = temp

  def roll_S(self):
    temp = self.top
    self.top = self.back
    self.back = self.bottom
    self.bottom = self.front
    self.front = temp

  def roll_W(self):
    temp = self.top
    self.top = self.right
    self.right = self.bottom
    self.bottom = self.left
    self.left = temp

  def roll_E(self):
    temp = self.top
    self.top = self.left
    self.left = self.bottom
    self.bottom = self.right
    self.right = temp

my_dice = Dice(raw_input().split(" "))
order = raw_input()
for i in xrange(len(order)):
  if order[i] == "E":
    my_dice.roll_E()
  elif order[i] == "N":
    my_dice.roll_N()
  elif order[i] == "S":
    my_dice.roll_S()
  elif order[i] == "W":
    my_dice.roll_W()
  else:
    continue

print my_dice.top

Submission status: Accepted

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

POSITIONS = ["top", "south", "east", "west", "north", "bottom"]


class Dice(object):

    def __init__(self, initial_faces):
        self.faces = {p: initial_faces[i] for i, p in enumerate(POSITIONS)}
        self.store_previous_faces()

    def store_previous_faces(self):
        self.previous_faces = self.faces.copy()

    def change_face(self, after, before):
        self.faces[after] = self.previous_faces[before]

    def change_faces(self, rotation):
        self.change_face(rotation[0], rotation[1])
        self.change_face(rotation[1], rotation[2])
        self.change_face(rotation[2], rotation[3])
        self.change_face(rotation[3], rotation[0])

    def roll(self, direction):
        self.store_previous_faces()
        if direction == "E":
            self.change_faces(["top", "west", "bottom", "east"])
        elif direction == "N":
            self.change_faces(["top", "south", "bottom", "north"])
        elif direction == "S":
            self.change_faces(["top", "north", "bottom", "south"])
        elif direction == "W":
            self.change_faces(["top", "east", "bottom", "west"])

    def rolls(self, directions):
        for d in directions:
            self.roll(d)

    def show_top(self):
        return self.faces["top"]


def main():
    dice = Dice(input().split())
    dice.rolls(input())
    print(dice.show_top())

if __name__ == "__main__":
    main()

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(object):

    def __init__(self, num):
        self.num = num

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

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

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

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


dice = Dice(map(int, raw_input().split()))
order = raw_input()
for i in range(len(order)):
    if order[i] == 'S':
        dice.rotate_S()
    elif order[i] == 'N':
        dice.rotate_N()
    elif order[i] == 'W':
        dice.rotate_W()
    elif order[i] == 'E':
        dice.rotate_E()

print dice.num[0]

Submission status: Accepted

Solution code:
class Dice(object):
    """docstring for Dice"""
    def __init__(self, numeric_column):
        self.numeric_column=numeric_column
    def roll_to_S_direction(self):
        self.numeric_column=[self.numeric_column[4],self.numeric_column[0],self.numeric_column[2],self.numeric_column[3],self.numeric_column[5],self.numeric_column[1]]
    def roll_to_N_direction(self):
        self.numeric_column=[self.numeric_column[1],self.numeric_column[5],self.numeric_column[2],self.numeric_column[3],self.numeric_column[0],self.numeric_column[4]]
    def roll_to_E_direction(self):
        self.numeric_column=[self.numeric_column[3],self.numeric_column[1],self.numeric_column[0],self.numeric_column[5],self.numeric_column[4],self.numeric_column[2]]
    def roll_to_W_direction(self):
        self.numeric_column=[self.numeric_column[2],self.numeric_column[1],self.numeric_column[5],self.numeric_column[0],self.numeric_column[4],self.numeric_column[3]]

dice=Dice(map(int,raw_input().split()))
direction=raw_input()
for i in direction:
    if i=='S': dice.roll_to_S_direction()
    elif i=='N': dice.roll_to_N_direction()
    elif i=='E': dice.roll_to_E_direction()
    else: dice.roll_to_W_direction()
print dice.numeric_column[0]

Submission status: Accepted

Solution code:
class Dice(object):
	def __init__(self,List):
		self.face=List
	
	def n_spin(self,List):
		temp=List[0]
		List[0]=List[1]
		List[1]=List[5]
		List[5]=List[4]
		List[4]=temp

	def s_spin(self,List):
		temp=List[0]
		List[0]=List[4]
		List[4]=List[5]
		List[5]=List[1]
		List[1]=temp

	def e_spin(self,List):
		temp=List[0]
		List[0]=List[3]
		List[3]=List[5]
		List[5]=List[2]
		List[2]=temp

	def w_spin(self,List):
		temp=List[0]
		List[0]=List[2]
		List[2]=List[5]
		List[5]=List[3]
		List[3]=temp

dice = Dice(map(int,raw_input().split()))
command = list(raw_input())
for k in command:
	if k=='N':
		dice.n_spin(dice.face)
	elif k=='S':
		dice.s_spin(dice.face)
	elif k=='E':
		dice.e_spin(dice.face)
	else:
		dice.w_spin(dice.face)
print dice.face[0]

Submission status: Accepted

Solution code:
class Dice:
    def __init__(self, num_list):
        self.vertical_faces = [num_list[0], num_list[1], num_list[5], num_list[4]]
        self.horizonal_faces = [num_list[0], num_list[3], num_list[5], num_list[2]]

    def roll(self, direction):
        if direction == 'N':
            self.vertical_faces = self.vertical_faces[1:] + self.vertical_faces[:1]
            self.horizonal_faces[0] = self.vertical_faces[0]
            self.horizonal_faces[2] = self.vertical_faces[2]
        elif direction == 'S':
            self.vertical_faces = self.vertical_faces[3:] + self.vertical_faces[:3]
            self.horizonal_faces[0] = self.vertical_faces[0]
            self.horizonal_faces[2] = self.vertical_faces[2]
        elif direction == 'E':
            self.horizonal_faces = self.horizonal_faces[1:] + self.horizonal_faces[:1]
            self.vertical_faces[0] = self.horizonal_faces[0]
            self.vertical_faces[2] = self.horizonal_faces[2]
        else:
            self.horizonal_faces = self.horizonal_faces[3:] + self.horizonal_faces[:3]
            self.vertical_faces[0] = self.horizonal_faces[0]
            self.vertical_faces[2] = self.horizonal_faces[2]

num_list = list(map(int, input().split()))

dice = Dice(num_list)

directions = input()

for i in directions:
    dice.roll(i)

print(dice.vertical_faces[0])

Submission status: Accepted

Solution code:
class Dice:
    def __init__(self, face_vals):
        self.faces = dict(zip(['top', 'south', 'east',
                               'west', 'north', 'bottom'], face_vals))

    def roll(self, direction):
        if direction == 'N':
            self.faces['top'], self.faces['south'], self.faces['bottom'], \
            self.faces['north'] = self.faces['south'], self.faces['bottom'], \
            self.faces['north'], self.faces['top']
        elif direction == 'S':
            self.faces['top'], self.faces['south'], self.faces['bottom'], \
            self.faces['north'] = self.faces['north'], self.faces['top'], \
            self.faces['south'], self.faces['bottom']
        elif direction == 'E':
            self.faces['top'], self.faces['east'], self.faces['bottom'], \
            self.faces['west'] = self.faces['west'], self.faces['top'], \
            self.faces['east'], self.faces['bottom']
        else:
            self.faces['top'], self.faces['east'], self.faces['bottom'], \
            self.faces['west'] = self.faces['east'], self.faces['bottom'], \
            self.faces['west'], self.faces['top']


face_vals = input().split()

dice = Dice(face_vals)

for i in input():
    dice.roll(i)

print(dice.faces['top'])

Submission status: Accepted

Solution code:
class Dice:
    def __init__(self, face_vals):
        self.faces = dict(zip(['top', 'front', 'right',
                               'left', 'back', 'bottom'], face_vals))

    def roll(self, direction):
        if direction == 'N':
            self.faces['top'], self.faces['front'], self.faces['bottom'], \
            self.faces['back'] = self.faces['front'], self.faces['bottom'], \
            self.faces['back'], self.faces['top']
        elif direction == 'S':
            self.faces['top'], self.faces['front'], self.faces['bottom'], \
            self.faces['back'] = self.faces['back'], self.faces['top'], \
            self.faces['front'], self.faces['bottom']
        elif direction == 'E':
            self.faces['top'], self.faces['right'], self.faces['bottom'], \
            self.faces['left'] = self.faces['left'], self.faces['top'], \
            self.faces['right'], self.faces['bottom']
        else:
            self.faces['top'], self.faces['right'], self.faces['bottom'], \
            self.faces['left'] = self.faces['right'], self.faces['bottom'], \
            self.faces['left'], self.faces['top']


face_vals = input().split()

dice = Dice(face_vals)

for i in input():
    dice.roll(i)

print(dice.faces['top'])

Submission status: Accepted

Solution code:
class diceClass:
    label = []
    def __init__(self,l):
        if len(l) == 6:
            self.label = l
    def move(self,c):
        if c.upper() == 'N':
            buf = []
            buf.append(self.label[1])
            buf.append(self.label[5])
            buf.append(self.label[2])
            buf.append(self.label[3])
            buf.append(self.label[0])
            buf.append(self.label[4])
            self.label = buf
        elif c.upper() == 'E':
            buf = []
            buf.append(self.label[3])
            buf.append(self.label[1])
            buf.append(self.label[0])
            buf.append(self.label[5])
            buf.append(self.label[4])
            buf.append(self.label[2])
            self.label = buf
        elif c.upper() == 'W':
            buf = []
            buf.append(self.label[2])
            buf.append(self.label[1])
            buf.append(self.label[5])
            buf.append(self.label[0])
            buf.append(self.label[4])
            buf.append(self.label[3])
            self.label = buf
        elif c.upper() == 'S':
            buf = []
            buf.append(self.label[4])
            buf.append(self.label[0])
            buf.append(self.label[2])
            buf.append(self.label[3])
            buf.append(self.label[5])
            buf.append(self.label[1])
            self.label = buf
    def get_label(self):
        return self.label[0]
in_line = raw_input().split()
dice = diceClass(in_line)
move = raw_input()
for c in move:
    dice.move(c)
print dice.get_label()

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 get_top(self):
        return self.top

    def rotate(self, directions):
        for direction in directions:
            if direction == 'S':
                self.prev_top = self.top
                self.top = self.north
                self.north = self.bottom
                self.bottom = self.south
                self.south = self.prev_top
            elif direction == 'E':
                self.prev_top = self.top
                self.top = self.west
                self.west = self.bottom
                self.bottom = self.east
                self.east = self.prev_top
            elif direction == 'W':
                self.prev_top = self.top
                self.top = self.east
                self.east = self.bottom
                self.bottom = self.west
                self.west = self.prev_top
            elif direction == 'N':
                self.prev_top = self.top
                self.top = self.south
                self.south = self.bottom
                self.bottom = self.north
                self.north = self.prev_top

dice = Dice(*map(int, input().split()))
dice.rotate(input())
print(dice.get_top())

Submission status: Accepted

Solution code:
#-*- coding:utf-8 -*-
#approach:
#????????????????????±??????N???S??????????????¨W???E??????????????¨????????????
rolls = raw_input().split()
order = raw_input().strip()
nsrolls = [rolls[0],rolls[1],rolls[5],rolls[4]]
werolls = [rolls[0],rolls[2],rolls[5],rolls[3]]
while True:
    if order == "":
        break
    o = order[0]
    if o=="N":
        tmp = nsrolls[0]
        nsrolls.pop(0)
        nsrolls.append(tmp)
        werolls[0]=nsrolls[0]
        werolls[2]=nsrolls[2]
    elif o=="S":
        tmp = nsrolls[-1]
        nsrolls.pop(-1)
        nsrolls.insert(0,tmp)
        werolls[0]=nsrolls[0]
        werolls[2]=nsrolls[2]
    elif o=="W":
        tmp = werolls[0]
        werolls.pop(0)
        werolls.append(tmp)
        nsrolls[0]=werolls[0]
        nsrolls[2]=werolls[2]
    elif o=="E":
        tmp = werolls[-1]
        werolls.pop(-1)
        werolls.insert(0,tmp)
        nsrolls[0]=werolls[0]
        nsrolls[2]=werolls[2]
    else:
        print "invalid order"
    order = order[1:]
print nsrolls[0]

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(object):
  def __init__(self, List):
    self.face = List

  def n_spin(self, List):
    temp = List[0]
    List[0] = List[1]
    List[1] = List[5]
    List[5] = List[4]
    List[4] = temp

  def s_spin(self, List):
    temp = List[0]
    List[0] = List[4]
    List[4] = List[5]
    List[5] = List[1]
    List[1] = temp

  def e_spin(self, List):
    temp = List[0]
    List[0] = List[3]
    List[3] = List[5]
    List[5] = List[2]
    List[2] = temp

  def w_spin(self, List):
    temp = List[0]
    List[0] = List[2]
    List[2] = List[5]
    List[5] = List[3]
    List[3] = temp

dice = Dice(map(int, raw_input().split()))
command = list(raw_input())
for c in command:
  if c == "N":
    dice.n_spin(dice.face)
  elif c == "S":
    dice.s_spin(dice.face)
  elif c == "E":
    dice.e_spin(dice.face)
  elif c == "W":
    dice.w_spin(dice.face)

print dice.face[0]