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:
import copy

class Dice:
    def __init__(self, numbers):
        self.dd = dict(zip(['U', 'S', 'E', 'W', 'N', 'B'], numbers))

    def next(self, o):
        old = copy.deepcopy(self.dd)
        if o == 'E':
            self.dd['B'] = old['E']
            self.dd['U'] = old['W']
            self.dd['E'] = old['U']
            self.dd['W'] = old['B']
        elif o == 'S':
            self.dd['B'] = old['S']
            self.dd['U'] = old['N']
            self.dd['S'] = old['U']
            self.dd['N'] = old['B']
        elif o == 'W':
            self.dd['B'] = old['W']
            self.dd['U'] = old['E']
            self.dd['E'] = old['B']
            self.dd['W'] = old['U']
        elif o == 'N':
            self.dd['B'] = old['N']
            self.dd['U'] = old['S']
            self.dd['S'] = old['B']
            self.dd['N'] = old['U']

dn = [int(n) for n in input().split()]
op = input()
ad = Dice(dn)

for o in op:
    ad.next(o)

print(ad.dd['U'])

Submission status: Accepted

Solution code:
class Dice():
    def __init__(self, nums):
        self.nums = nums
        self.top, self.front, self.right = 0, 1, 2

    def move(self, op):
        for c in op:
            if c == 'N':
                self.top, self.front = self.front, 5 - self.top
            elif c == 'S':
                self.top, self.front = 5 - self.front, self.top
            elif c == 'E':
                self.top, self.right = 5 - self.right, self.top
            else:
                self.top, self.right = self.right, 5 - self.top

dice = Dice([int(n) for n in input().split()])
dice.move(input())
print(dice.nums[dice.top])

Submission status: Accepted

Solution code:
n1,n2,n3,n4,n5,n6=map(int,raw_input().split())
act=raw_input()
for i in act:
    if i=="N":
        n11=n1
        n1=n2
        n2=n6
        n6=n5
        n5=n11
    elif i=="S":
        n11=n1
        n1=n5
        n5=n6
        n6=n2
        n2=n11
    elif i=="E":
        n11=n1
        n1=n4
        n4=n6
        n6=n3
        n3=n11
    else :
        n11=n1
        n1=n3
        n3=n6
        n6=n4
        n4=n11
print(n1)

Submission status: Accepted

Solution code:
class Dice:
  def __init__(self):
    self.top = 1
    self.front = 2
    self.left = 4

  @property
  def bottom(self):
    return 7 - self.top

  @property
  def back(self):
    return 7 - self.front

  @property
  def right(self):
    return 7 - self.left

  def move(self, direction):
    if direction == 'N':
      bottom = self.bottom
      self.top = self.front
      self.front = bottom
    elif direction == 'W':
      right = self.right
      self.left = self.top
      self.top = right
    elif direction == 'E':
      bottom = self.bottom
      self.top = self.left
      self.left = bottom
    elif direction == 'S':
      back = self.back
      self.front = self.top
      self.top = back

  def __repr__(self):
    print(self.__dict__)

dice = Dice()
numbers = input().split()
for cmd in input():
  dice.move(cmd)
print(numbers[dice.top - 1])

Submission status: Accepted

Solution code:
class Dice():
    def __init__(self, nums):
        self.nums = nums
        self.top, self.front, self.right = 0, 1, 2
 
    def move(self, op):
        for c in op:
            if c == 'N':
                self.top, self.front = self.front, 5 - self.top
            elif c == 'S':
                self.top, self.front = 5 - self.front, self.top
            elif c == 'E':
                self.top, self.right = 5 - self.right, self.top
            else:
                self.top, self.right = self.right, 5 - self.top
 
dice = Dice([int(n) for n in input().split()])
dice.move(input())
print(dice.nums[dice.top])

Submission status: Accepted

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

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

    def roll(self, s):
        for i in s:
            if i == 'E':
                self.rollE()
            elif i == 'N':
                self.rollN()
            elif i == 'S':
                self.rollS()
            elif i == 'W':
                self.rollW()

    def rollE(self):
        tmp         =   self.top
        self.top    =   self.left
        self.left   =   self.bottom
        self.bottom =   self.right
        self.right  =   tmp

    def rollN(self):
        tmp         =   self.top
        self.top    =   self.front
        self.front  =   self.bottom
        self.bottom =   self.back
        self.back   =   tmp

    def rollS(self):
        tmp         =   self.top
        self.top    =   self.back
        self.back   =   self.bottom
        self.bottom =   self.front
        self.front  =   tmp

    def rollW(self):
        tmp         =   self.top
        self.top    =   self.right
        self.right  =   self.bottom
        self.bottom =   self.left
        self.left   =   tmp

if __name__ == "__main__":
    a = map(int, raw_input().split())
    s = str(raw_input())
    dice = dice_class(a[0], a[1], a[2], a[3], a[4], a[5])
    dice.roll(s)
    print dice.top

Submission status: Accepted

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

class dice_class:
    def __init__(self, list):
        self.num = list

    def roll(self, s):
        for i in s:
            if i == 'E':
                self.rollE()
            elif i == 'N':
                self.rollN()
            elif i == 'S':
                self.rollS()
            elif i == 'W':
                self.rollW()

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

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

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

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


if __name__ == "__main__":
    dice = dice_class(map(int, raw_input().split()))
    s = str(raw_input())
    dice.roll(s)
    print dice.num[0]

Submission status: Accepted

Solution code:
class Dice:
    def __init__(self):
        self.front = '1'
        self.back = '6'
        self.top = '5'
        self.bottom = '2'
        self. right = '3'
        self.left = '4'
    def turnRight(self):
        temp = self.top
        self.top = self.left
        self.left = self.bottom
        self.bottom = self.right
        self.right = temp
        return self.top
    def turnLeft(self):
        temp = self.top
        self.top = self.right
        self.right = self.bottom
        self.bottom = self.left
        self.left = temp
        return self.top
    def turnFront(self):
        temp = self.top
        self.top = self.back
        self.back = self.bottom
        self.bottom = self.front
        self.front = temp
        return self.top
    def turnBack(self):
        temp = self.top
        self.top = self.front
        self.front = self.bottom
        self.bottom = self.back
        self.back = temp
        return self.top

mydice = Dice()
mydice.top, mydice.front, mydice.right, mydice.left, mydice.back, mydice.bottom = input().split()
orders = input()

for order in orders:
    if order == 'E':
        mydice.turnRight()
    elif order == 'W':
        mydice.turnLeft()
    elif order == 'S':
        mydice.turnFront()
    elif order == 'N':
        mydice.turnBack()
    else:
        print('Input error')
        break
print(mydice.top)

Submission status: Accepted

Solution code:
class Dice:

    def __init__(self):
        d = map(int, raw_input().split(" "))
        self.c = raw_input()
        self.rows = [d[0], d[4], d[5], d[1]]
        self.cols = [d[0], d[2], d[5], d[3]]

    def __move_next(self, x, y):
        temp = y.pop(0)
        y.append(temp)
        x[0] = y[0]
        x[2] = y[2]

    def __move_prev(self, x, y):
        temp = y.pop(3)
        y.insert(0, temp)
        x[0] = y[0]
        x[2] = y[2]

    def execute(self):
        for i in self.c:
            self.__move(i, self.rows, self.cols)

    def __move(self, com, x, y):
        if com == "N":
            self.__move_prev(y, x)
        elif com == "S":
            self.__move_next(y, x)
        elif com == "E":
            self.__move_prev(x, y)
        elif com == "W":
            self.__move_next(x, y)

    def print_top(self):
        print self.rows[0]

dice = Dice()
dice.execute()
dice.print_top()

Submission status: Accepted

Solution code:
class Dice:
    def __init__(self,u,s,e,w,n,d):
        self.n = n
        self.e = e
        self.s = s
        self.w = w
        self.u = u
        self.d = d
    def roll(self,dir):
        if (dir == "N"):
            tmp = self.n
            self.n = self.u
            self.u = self.s
            self.s = self.d
            self.d = tmp
        elif (dir == "E"):
            tmp = self.e
            self.e = self.u
            self.u = self.w
            self.w = self.d
            self.d = tmp
        elif (dir == "S"):
            tmp = self.s
            self.s = self.u
            self.u = self.n
            self.n = self.d
            self.d = tmp
        elif (dir == "W"):
            tmp = self.w
            self.w = self.u
            self.u = self.e
            self.e = self.d
            self.d = tmp

spots = raw_input().split()
operations = raw_input()

dice = Dice(*spots)
for i in operations:
    dice.roll(i)

print dice.u

Submission status: Accepted

Solution code:
def move_dice(d, dir):
    if(dir == 'N'):
        d[0], d[1], d[4], d[5] = d[1], d[5], d[0], d[4]
    if(dir == 'S'):
        d[0], d[1], d[4], d[5] = d[4], d[0], d[5], d[1]
    if(dir == 'E'):
        d[0], d[2], d[3], d[5] = d[3], d[0], d[5], d[2]
    if(dir == 'W'):
        d[0], d[2], d[3], d[5] = d[2], d[5], d[0], d[3]


dice = list(map(int, input().split()))
command = input()
for c in command:
    move_dice(dice, c)
print(dice[0])

Submission status: Accepted

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

    def north(self):
        self.change([2, 6, 3, 4, 1, 5])

    def south(self):
        self.change([5, 1, 3, 4, 6, 2])

    def east(self):
        self.change([4, 2, 1, 6, 5, 3])

    def west(self):
        self.change([3, 2, 6, 1, 5, 4])

    def change(self, convert):
        result = []
        for i in range(6):
            result.append(self.labels[convert[i] - 1])

        self.labels = result


dice = Dice(list(map(int, input().split())))
for direction in input():
    if direction == 'N':
        dice.north()
    if direction == 'S':
        dice.south()
    if direction == 'E':
        dice.east()
    if direction == 'W':
        dice.west()

print(dice.labels[0])

Submission status: Accepted

Solution code:
#   ?¬?????±??????????????????????????????????????????¢??????????????\??¬????????§????????????????????°??????

#   ????????????????????¨????????????
dice = [0 for i in range(6)]
#   ??????????????¢????¨??????\???????????????
dice = list(input().split())
#   ??¢????????????????¨??????\???????????????
order = list(input())

for i in range(0, len(order)):
    #   S:5->1->2->6,5???1,1???2,,,
    if order[i] == "S":
        temp = dice[0]
        dice[0] = dice[4]
        dice[4] = dice[5]
        dice[5] = dice[1]
        dice[1] = temp
    #   E:4->1->3->6
    elif order[i] == "E":
        temp = dice[0]
        dice[0] = dice[3]
        dice[3] = dice[5]
        dice[5] = dice[2]
        dice[2] = temp
    #   W:3->1->4->6
    elif order[i] == "W":
        temp = dice[0]
        dice[0] = dice[2]
        dice[2] = dice[5]
        dice[5] = dice[3]
        dice[3] = temp
    #   N:2->1->5->6
    elif order[i] == "N":
        temp = dice[0]
        dice[0] = dice[1]
        dice[1] = dice[5]
        dice[5] = dice[4]
        dice[4] = temp
print("{0}".format(dice[0]))

Submission status: Accepted

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

def rot(d, r):
    if r == 'N':
        return [d[1], d[5], d[2], d[3], d[0], d[4]]
    if r == 'E':
        return [d[3], d[1], d[0], d[5], d[4], d[2]]
    if r == 'W':
        return [d[2], d[1], d[5], d[0], d[4], d[3]]
    if r == 'S':
        return [d[4], d[0], d[2], d[3], d[5], d[1]]
    return d

for r in rs:
    ns = rot(ns, r)

print(ns[0])

Submission status: Accepted

Solution code:
# 23-Structure_and_Class-Dice_I.py

# ???????????? I
# ?¬?????±??????????????????????????????????????????¢??????????????\??¬????????§????????????????????°????????????????????????????????????

# ????????????????????¢??????????????¨????????? 1 ?????? 6 ????????????????????????????????????????????????
# ??\?????¨??????????????????????????¢?????????????????????????????°?????¨?????¢?????????????????????????????????????????§???
# ????????????????????¢?????°?????????????????????????????????
# ????????\??¬????????§??????????????¶?????????????????¨?????????????????????????????§?????????????????????????????????????????¨????????????

# Input
# ?????????????????¢?????°???????????????????????????????????????????????????????????§?????????????????????

# ???????????????????????¨????????????????????????????????????????????????????????????????????????????????????????????¨????????? E???N???S???W ????????????????????§??????

# Output
# ???????????????????????????????????????????????????????????¢?????°???????????????????????????????????????

# Constraints
# 0???0??? ??\?????????????????????????????¢?????°??? ???100???100
# 0???0??? ???????????¨????????????????????? ???100???100
# Note
# ?¶???????????????? Dice III, Dice IV ??§???????????°????????????????????±????????§???????????????????????????????§?????????§?????????????????????????????????

# Sample Input 1
# 1 2 4 8 16 32
# SE
# Sample Output 1
# 8
# ?????¢??? 1, 2, 4, 8, 16, 32 ??¨??????????????????????????? S ??????????????¢???????????????E ??????????????¢????????¨????????¢?????°?????? 8 ??????????????????



# Sample Input 2
# 1 2 4 8 16 32
# EESWN
# Sample Output 2
# 32

class Dice:
	def __init__(self, dice_num):
		self.side_top=1
		self.side_bot=6
		self.side_Nor=5
		self.side_Eas=3
		self.side_Sau=2
		self.side_Wes=4
		self.dice_num = dice_num

	def op_N(self):
		self.side_top, self.side_bot, self.side_Nor, self.side_Sau =\
		self.side_Sau, self.side_Nor, self.side_top, self.side_bot

	def op_E(self):
		self.side_top, self.side_bot, self.side_Eas, self.side_Wes =\
		self.side_Wes, self.side_Eas, self.side_top, self.side_bot

	def op_S(self):
		self.side_top, self.side_bot, self.side_Nor, self.side_Sau =\
		self.side_Nor, self.side_Sau, self.side_bot, self.side_top

	def op_W(self):
		self.side_top, self.side_bot, self.side_Eas, self.side_Wes =\
		self.side_Eas, self.side_Wes, self.side_bot, self.side_top

	def print_side_top(self):
		print( dice_num[self.side_top-1] )

	def print_side_all(self):
		print( "top:{}, bot:{}, Nor:{}, Eas{}, Sau:{}, Wes,{}.".format(self.side_top, self.side_bot, self.side_Nor, self.side_Eas, self.side_Sau, self.side_Wes ) )

dice_num = list( map(int, input().split()))
op = input()

dice_roll = Dice(dice_num) 
for i in op:
	if i == "N":
		dice_roll.op_N()
	elif i =="E":
		dice_roll.op_E()
	elif i =="S":
		dice_roll.op_S()
	elif i =="W":
		dice_roll.op_W()
	else:
		print("?????°??°")

dice_roll.print_side_top()

Submission status: Accepted

Solution code:
# 23-Structure_and_Class-Dice_I.py

# ???????????? I
# ?¬?????±??????????????????????????????????????????¢??????????????\??¬????????§????????????????????°????????????????????????????????????

# ????????????????????¢??????????????¨????????? 1 ?????? 6 ????????????????????????????????????????????????
# ??\?????¨??????????????????????????¢?????????????????????????????°?????¨?????¢?????????????????????????????????????????§???
# ????????????????????¢?????°?????????????????????????????????
# ????????\??¬????????§??????????????¶?????????????????¨?????????????????????????????§?????????????????????????????????????????¨????????????

# Input
# ?????????????????¢?????°???????????????????????????????????????????????????????????§?????????????????????

# ???????????????????????¨????????????????????????????????????????????????????????????????????????????????????????????¨????????? E???N???S???W ????????????????????§??????

# Output
# ???????????????????????????????????????????????????????????¢?????°???????????????????????????????????????

# Constraints
# 0???0??? ??\?????????????????????????????¢?????°??? ???100???100
# 0???0??? ???????????¨????????????????????? ???100???100
# Note
# ?¶???????????????? Dice III, Dice IV ??§???????????°????????????????????±????????§???????????????????????????????§?????????§?????????????????????????????????

# Sample Input 1
# 1 2 4 8 16 32
# SE
# Sample Output 1
# 8
# ?????¢??? 1, 2, 4, 8, 16, 32 ??¨??????????????????????????? S ??????????????¢???????????????E ??????????????¢????????¨????????¢?????°?????? 8 ??????????????????



# Sample Input 2
# 1 2 4 8 16 32
# EESWN
# Sample Output 2
# 32

#------------------------------------------------------------------------------------------
# class Dice:
# 	def __init__(self, dice_num):
# 		self.side_top=1
# 		self.side_bot=6
# 		self.side_Nor=5
# 		self.side_Eas=3
# 		self.side_Sau=2
# 		self.side_Wes=4
# 		self.dice_num = dice_num

# 	def op_N(self):
# 		self.side_top, self.side_bot, self.side_Nor, self.side_Sau =\
# 		self.side_Sau, self.side_Nor, self.side_top, self.side_bot

# 	def op_E(self):
# 		self.side_top, self.side_bot, self.side_Eas, self.side_Wes =\
# 		self.side_Wes, self.side_Eas, self.side_top, self.side_bot

# 	def op_S(self):
# 		self.side_top, self.side_bot, self.side_Nor, self.side_Sau =\
# 		self.side_Nor, self.side_Sau, self.side_bot, self.side_top

# 	def op_W(self):
# 		self.side_top, self.side_bot, self.side_Eas, self.side_Wes =\
# 		self.side_Eas, self.side_Wes, self.side_bot, self.side_top

# 	def print_side_top(self):
# 		print( dice_num[self.side_top-1] )

# 	def print_side_all(self):
# 		print( "top:{}, bot:{}, Nor:{}, Eas{}, Sau:{}, Wes,{}.".format(self.side_top, self.side_bot, self.side_Nor, self.side_Eas, self.side_Sau, self.side_Wes ) )


# dice_num = list( map(int, input().split()))

# dice_roll = Dice(dice_num) 
# for i in input():
# 	if i == "N":
# 		dice_roll.op_N()
# 	elif i =="E":
# 		dice_roll.op_E()
# 	elif i =="S":
# 		dice_roll.op_S()
# 	elif i =="W":
# 		dice_roll.op_W()
# 	else:
# 		print("?????°??°")

# dice_roll.print_side_top()

#------------------------------------------------------------------------------------------

class Dice:
	def __init__(self, dice_num):	  # 1    2    3    4    5    6
		self.dice_state=[1,6,5,3,2,4] #[top, bot, nor, eas, sau, wes]
		self.dice_num = dice_num

	def op_N(self):
		self.dice_state = [ self.dice_state[i-1] for i in [5,3,1,4,2,6] ]

	def op_E(self):
		self.dice_state = [ self.dice_state[i-1] for i in [6,4,3,1,5,2] ]

	def op_S(self):
		self.dice_state = [ self.dice_state[i-1] for i in [3,5,2,4,1,6] ]

	def op_W(self):
		self.dice_state = [ self.dice_state[i-1] for i in [4,6,3,2,5,1] ]

	def get_state_top(self):
		# print("dice_roll.get_state_top", self.dice_state[0])
		return self.dice_state[0]

	def get_num_top(self):
		return self.dice_num[self.dice_state[0]-1]

	def print_side_top(self):
		print( self.dice_num[self.dice_state[0]-1] )

	def print_side_all(self):
		print( "top:{}, bot:{}, Nor:{}, Eas{}, Sau:{}, Wes,{}.".format(self.side_top, self.side_bot, self.side_Nor, self.side_Eas, self.side_Sau, self.side_Wes ) )


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

dice_roll = Dice(dice_num) 

Func_set = {'N': dice_roll.op_N, 'W': dice_roll.op_W, 'E': dice_roll.op_E, 'S': dice_roll.op_S}

for i in input():
	Func_set[i]()

dice_roll.print_side_top()

Submission status: Accepted

Solution code:
face = map(int, raw_input().split())
order = raw_input()

dice = [ [ 0, face[0] ],
              [ 1, face[1] ],
              [ 2, face[2] ],
              [ 3, face[3] ],
              [ 4, face[4] ],
              [ 5, face[5] ]]
temp = 0

for i in order:
    if i == 'N':
        temp = dice[0][1]
        dice[0][1] = dice[1][1]
        dice[1][1] = dice[5][1]
        dice[5][1] = dice[4][1]
        dice[4][1] = temp
    if i == 'E':
        temp = dice[0][1]
        dice[0][1] = dice[3][1]
        dice[3][1] = dice[5][1]
        dice[5][1] = dice[2][1]
        dice[2][1] = temp
    if i == 'S':
        temp = dice[0][1]
        dice[0][1] = dice[4][1]
        dice[4][1] = dice[5][1]
        dice[5][1] = dice[1][1]
        dice[1][1] = temp
    if i == 'W':
        temp = dice[0][1]
        dice[0][1] = dice[2][1]
        dice[2][1] = dice[5][1]
        dice[5][1] = dice[3][1]
        dice[3][1] = temp

print dice[0][1]

Submission status: Accepted

Solution code:

class dise:
    def __init__(self, label):
        self.label1 = label[0]
        self.label2 = label[1]
        self.label3 = label[2]
        self.label4 = label[3]
        self.label5 = label[4]
        self.label6 = label[5]
    
    def N_rotation(self):
        reg = self.label1
        self.label1 = self.label2
        self.label2 = self.label6
        self.label6 = self.label5
        self.label5 = reg
        
    def E_rotation(self):
        reg = self.label1
        self.label1 = self.label4
        self.label4 = self.label6
        self.label6 = self.label3
        self.label3 = reg
        
    def S_rotation(self):
        reg = self.label1
        self.label1 = self.label5
        self.label5 = self.label6
        self.label6 = self.label2
        self.label2 = reg
        
    def W_rotation(self):
        reg = self.label1
        self.label1 = self.label3
        self.label3 = self.label6
        self.label6 = self.label4
        self.label4 = reg

dise1 = dise(input().split())
order = list(input())

for i in order:
    if i == 'N':
        dise1.N_rotation()
    elif i == 'E':
        dise1.E_rotation()
    elif i == 'S':
        dise1.S_rotation()
    elif i == 'W':
        dise1.W_rotation()

print(dise1.label1)

Submission status: Accepted

Solution code:
class dice:
    def __init__(self,label):
        self.d = label
    def roll(self,op):
        d = self.d
        if   op=='N': self.d = [d[1],d[5],d[2],d[3],d[0],d[4]]
        elif op=='E': self.d = [d[3],d[1],d[0],d[5],d[4],d[2]]
        elif op=='W': self.d = [d[2],d[1],d[5],d[0],d[4],d[3]]
        elif op=='S': self.d = [d[4],d[0],d[2],d[3],d[5],d[1]]
    def print(self):
        print(self.d[0])

label = list(map(int,input().split()))
op_list = list(input())
d0 = dice(label)
for op in op_list:
    d0.roll(op)
d0.print()

Submission status: Accepted

Solution code:
import sys
import math

def str_input():
    S = raw_input()
    if S[len(S)-1] == "\r":
        return S[:len(S)-1]
    return S

def float_to_str(num):
    return str("{:.10f}".format(num))

def list_input(tp):
    return map(tp, str_input().split())

# # # # # # # # # # # # # # # # # # # # # # # # #

class Dice:
    pip = [0 for i in xrange(6)]

    def __init__(self, arg):
        self.pip = arg

    def rollDir(self, dr):
        nextPip = [0 for i in xrange(6)]
        if dr == "N":
            nextPip[0] = self.pip[1]
            nextPip[1] = self.pip[5]
            nextPip[2] = self.pip[2]
            nextPip[3] = self.pip[3]
            nextPip[4] = self.pip[0]
            nextPip[5] = self.pip[4]
        elif dr == "E":
            nextPip[0] = self.pip[3]
            nextPip[1] = self.pip[1]
            nextPip[2] = self.pip[0]
            nextPip[3] = self.pip[5]
            nextPip[4] = self.pip[4]
            nextPip[5] = self.pip[2]
        self.pip = nextPip

    def roll(self, dr):
        if dr == "N" or dr == "E":
            self.rollDir(dr)
        elif dr == "S":
            self.rollDir("N")
            self.rollDir("N")
            self.rollDir("N")
        elif dr == "W":
            self.rollDir("E")
            self.rollDir("E")
            self.rollDir("E")

dice = Dice(list_input(int))
command = str_input()

for x in command:
    dice.roll(x)

print dice.pip[0]

Submission status: Accepted

Solution code:
def rotate(dice,d):
    if d == "N":
        temp = dice[0]
        dice[0] = dice[1]
        dice[1] = dice[5]
        dice[5] = dice[4]
        dice[4] = temp
    elif d == "E":
        temp = dice[0]
        dice[0] = dice[3]
        dice[3] = dice[5]
        dice[5] = dice[2]
        dice[2] = temp
    elif d == "W":
        temp = dice[0]
        dice[0] = dice[2]
        dice[2] = dice[5]
        dice[5] = dice[3]
        dice[3] = temp
    elif d == "S":
        temp = dice[0]
        dice[0] = dice[4]
        dice[4] = dice[5]
        dice[5] = dice[1]
        dice[1] = temp
    return dice

dice = input().split()
dArr = list(input())
for i in range(len(dArr)):
    dice = rotate(dice,dArr[i])
print(dice[0])

Submission status: Accepted

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

    def move_E(self):
        self.copy = self.num.copy() 
        for i,j in zip([0,2,5,3],[3,0,2,5]):
            self.num[i] = self.copy[j]

    def move_W(self):
        self.copy = self.num.copy()
        for i,j in zip([0,3,5,2],[2,0,3,5]):
            self.num[i] = self.copy[j]

    def move_N(self):
        self.copy = self.num.copy()
        for i,j in zip([0,1,5,4],[1,5,4,0]):
            self.num[i] = self.copy[j]

    def move_S(self):
        self.copy = self.num.copy()
        for i,j in zip([0,1,5,4],[4,0,1,5]):
            self.num[i] = self.copy[j]



number = list(map(int,input().split()))
#number = [1,2,4,8,16,32]
#print("1 2 3 4 5 6")
# ?????????????????????
dice = Dice(number)

for order in input():
    if order == 'S':
        dice.move_S()
    elif order == 'N':
        dice.move_N()
    elif order == 'W':
        dice.move_W()
    else:
        dice.move_E()

# ?????????????????¶????????????
#print(dice.num)

print(dice.num[0])

Submission status: Accepted

Solution code:
class dice:
    def __init__(self,label):
        self.top, self.front, self.right, self.left, self.rear, self.bottom \
                = label
    def roll(self,op):
        if   op=='N': self.top, self.front, self.bottom, self.rear = \
                                self.front, self.bottom, self.rear , self.top
        elif op=='E': self.top, self.left , self.bottom, self.right = \
                                self.left , self.bottom, self.right, self.top
        elif op=='W': self.top, self.right, self.bottom, self.left = \
                                self.right, self.bottom, self.left , self.top
        elif op=='S': self.top, self.rear , self.bottom, self.front = \
                                self.rear , self.bottom, self.front, self.top
    def print_top(self): print(self.top)
 
label = list(map(int,input().split()))
op_list = list(input())
d = dice(label)
for op in op_list:
    d.roll(op)
d.print_top()

Submission status: Accepted

Solution code:
class Dice:
    def __init__(self):
        self.numbers = map(int, raw_input().split())
        
    def roll(self, direction):
        if direction == "N":
            before_inds = [0, 1, 5, 4]
            after_inds  = [1, 5, 4, 0]
        elif direction == "S":
            before_inds = [0, 1, 5, 4]
            after_inds  = [4, 0, 1, 5]
        elif direction == "E":
            before_inds = [0, 2, 5, 3]
            after_inds  = [3, 0, 2, 5]
        elif direction == "W":
            before_inds = [0, 2, 5, 3]
            after_inds  = [2, 5, 3, 0]
        else:
            return False
        changed = [self.numbers[i] for i in after_inds]
        for c_i, n_i in enumerate(before_inds):
            self.numbers[n_i] = changed[c_i]
        return True
        
dice = Dice()
for d in raw_input():
    dice.roll(d)
    
print dice.numbers[0]

Submission status: Accepted

Solution code:
class Dice:
    def __init__(self):
        # top, front, right, left, back, bottom
        self.numbers = map(int, raw_input().split())
    
    @property
    def top(self):
        return self.numbers[0]
    
    @property
    def front(self):
        return self.numbers[1]
        
    @property
    def right(self):
        return self.numbers[2]
        
    @property
    def left(self):
        return self.numbers[3]
    
    @property
    def back(self):
        return self.numbers[4]
        
    @property
    def bottom(self):
        return self.numbers[5]

    def roll(self, direction):
        if direction == "N":
            before_inds = [0, 1, 5, 4]
            after_inds  = [1, 5, 4, 0]
        elif direction == "S":
            before_inds = [0, 1, 5, 4]
            after_inds  = [4, 0, 1, 5]
        elif direction == "E":
            before_inds = [0, 2, 5, 3]
            after_inds  = [3, 0, 2, 5]
        elif direction == "W":
            before_inds = [0, 2, 5, 3]
            after_inds  = [2, 5, 3, 0]
        else:
            return False
        changed = [self.numbers[i] for i in after_inds]
        for c_i, n_i in enumerate(before_inds):
            self.numbers[n_i] = changed[c_i]
        return True
        
dice = Dice()
for d in raw_input():
    dice.roll(d)
    
print dice.top

Submission status: Accepted

Solution code:
class Dice:
    def __init__(self,pips):
        self.top = pips[0]
        self.south = pips[1]
        self.east = pips[2]
        self.west = pips[3]
        self.north =pips[4]
        self.bottom=pips[5]
    def show_top(self):
        print(self.top)
    def n(self):
        tmp = self.top
        self.top = self.south
        self.south = self.bottom
        self.bottom = self.north
        self.north = tmp
    def s(self):
        tmp = self.top
        self.top = self.north
        self.north = self.bottom
        self.bottom = self.south
        self.south = tmp
    def e(self):
        tmp = self.top
        self.top = self.west
        self.west = self.bottom
        self.bottom = self.east
        self.east = tmp
    def w(self):
        tmp = self.top
        self.top = self.east
        self.east = self.bottom
        self.bottom = self.west
        self.west = tmp

pips = [int(x) for x in input().split()]
dice = Dice(pips)
move = input()
for m in move:
    if m == "N":
        dice.n()
    if m == "S":
        dice.s()
    if m == "E":
        dice.e()
    if m == "W":
        dice.w()

dice.show_top()