Problem:


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

Dice I

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

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

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

Input

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

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

Output

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

Constraints

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

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

Sample Input 1

1 2 4 8 16 32
SE

Sample Output 1

8

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

Sample Input 2

1 2 4 8 16 32
EESWN

Sample Output 2

32



Sample input:
1 2 4 8 16 32
SE


Sample output:
8

Submission status: Accepted

Solution code:
def north(d):
	d[0], d[1], d[5], d[4] = d[1], d[5], d[4], d[0]
	
def south(d):
	d[0], d[4], d[5], d[1] = d[4], d[5], d[1], d[0]
	
def east(d):
	d[0], d[3], d[5], d[2] = d[3], d[5], d[2], d[0]
	
def west(d):
	d[0], d[2], d[5], d[3] = d[2], d[5], d[3], d[0]

F = {'N': north, 'S': south, 'W': west, 'E': east}

d, os = list(map(int, input().split())), input()

for o in os:
	F[o](d)

print(d[0])

Submission status: Accepted

Solution code:
class dice:
    def __init__(self,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=[int(x) for x in input().split()]
oplist=list(input())
d=dice(label)
for op in oplist:
    d.roll(op)
d.print_top()

Submission status: Accepted

Solution code:
class Dice():

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

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

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

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

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

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


def main():
    dice = Dice([int(x) for x in input().split()])
    cmd = list(input())
    for c in cmd:
        if c == 'N':
            dice.north()
        elif c == 'W':
            dice.west()
        elif c == 'E':
            dice.east()
        elif c == 'S':
            dice.south()
    print(dice.label[0])


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
class Dice():

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

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

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

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

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

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


def main():
    dice = Dice([int(x) for x in input().split()])
    for c in input():
        if c == 'N':
            dice.north()
        elif c == 'W':
            dice.west()
        elif c == 'E':
            dice.east()
        elif c == 'S':
            dice.south()
    print(dice.label[0])


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
class Dice:
    def __init__(self, labels):
        self.up = labels[0]
        self.front = labels[1]
        self.right = labels[2]
        self.left = labels[3]
        self.back = labels[4]
        self.down = labels[5]
    def east(self):
        self.up, self.right, self.down, self.left = self.left, self.up, self.right, self.down
    def north(self):
        self.up, self.back, self.down, self.front = self.front, self.up, self.back, self.down
    def south(self):
        self.up, self.front, self.down, self.back = self.back, self.up, self.front, self.down
    def west(self):
        self.up, self.left, self.down, self.right = self.right, self.up, self.left, self.down

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

Submission status: Accepted

Solution code:
# coding: utf-8
# ?????????????????¨????????????
class Dice(object):
	def __init__(self):
		# ???????????????????????°
		# ????????¶???
		self.x = [2, 5]
		self.y = [3, 4]
		self.z = [1, 6]
		SN = {'S': 0, 'N': 1}
		WE = {'W': 0, 'E': 1}
		pass

	def rotate(self, _dir):
		def rot(_k, _r):
			return list(reversed(_r)), _k

		if _dir=='N':
			self.x, self.z = rot(self.x, self.z)
		elif _dir=='S':
			self.z, self.x = rot(self.z, self.x)
		elif _dir=='E':
			self.z, self.y = rot(self.z, self.y)
		elif _dir=='W':
			self.y, self.z = rot(self.y, self.z)
		else:
			pass

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


if __name__=="__main__":
	dice = Dice()
	val = list(map(int, input().split()))
	dr = input()
	for d in dr:
		dice.rotate(d)
	print(val[dice.top()-1])

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:
Dice=[int(i) for i in input().split()]
words=input()
for word in words:
    if word=='N':
        num=Dice[0]
        Dice[0]=Dice[1]
        Dice[1]=Dice[5]
        Dice[5]=Dice[4]
        Dice[4]=num
    if word=='E':
        num=Dice[0]
        Dice[0]=Dice[3]
        Dice[3]=Dice[5]
        Dice[5]=Dice[2]
        Dice[2]=num
    if word=='W':
        num=Dice[0]
        Dice[0]=Dice[2]
        Dice[2]=Dice[5]
        Dice[5]=Dice[3]
        Dice[3]=num
    if word=='S':
        num=Dice[0]
        Dice[0]=Dice[4]
        Dice[4]=Dice[5]
        Dice[5]=Dice[1]
        Dice[1]=num
print(Dice[0])

Submission status: Accepted

Solution code:
class Dice:
    def __init__(self, n1, n2, n3, n4, n5, n6):
        self.elements = [n1, n2, n3, n4, n5, n6]

    def rotateW(self):
        n5 = self.elements[0]
        n1 = self.elements[2]
        n3 = self.elements[5]
        n6 = self.elements[4]
        self.elements[4] = n5
        self.elements[0] = n1
        self.elements[2] = n3
        self.elements[5] = n6

    def rotateN(self):
        n2 = self.elements[0]
        n1 = self.elements[3]
        n4 = self.elements[5]
        n6 = self.elements[1]
        self.elements[1] = n2
        self.elements[0] = n1
        self.elements[3] = n4
        self.elements[5] = n6


    def rotateS(self):
        n4 = self.elements[0]
        n1 = self.elements[1]
        n2 = self.elements[5]
        n6 = self.elements[3]
        self.elements[3] = n4
        self.elements[0] = n1
        self.elements[1] = n2
        self.elements[5] = n6

    def rotateE(self):
        n3 = self.elements[0]
        n1 = self.elements[4]
        n5 = self.elements[5]
        n6 = self.elements[2]
        self.elements[2] = n3
        self.elements[0] = n1
        self.elements[4] = n5
        self.elements[5] = n6

elements = map(int, raw_input().split(" "))
dice = Dice(elements[0], elements[4], elements[2], elements[1], elements[3], elements[5])
rule = raw_input()

for i in rule:
    if i == "S": dice.rotateS()
    elif i == "W": dice.rotateW()
    elif i == "N": dice.rotateN()
    elif i == "E": dice.rotateE()

print(str(dice.elements[0]))

Submission status: Accepted

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

    def roll(self, s):
        for f in s:
            n = self.f[:]
            if f == 'E':
                t = n[0]
                n[0] = n[3]
                n[3] = n[5]
                n[5] = n[2]
                n[2] = t
            elif f == 'W':
                t = n[0]
                n[0] = n[2]
                n[2] = n[5]
                n[5] = n[3]
                n[3] = t
            elif f == 'N':
                t = n[0]
                n[0] = n[1]
                n[1] = n[5]
                n[5] = n[4]
                n[4] = t
            else:
                t = n[0]
                n[0] = n[4]
                n[4] = n[5]
                n[5] = n[1]
                n[1] = t
            self.f = n

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

d = Dice(list(map(int, input().split())))
r = input()
d.roll(r)
print(d.top())

Submission status: Accepted

Solution code:
class Dice(object):
    def __init__(self):
        self.upside = 1
        self.frontside = 2
        self.rightside = 3
        self.backside = 5
        self.leftside = 4
        self.downside = 6
		
    def throwDice(self,dir):
        up = self.upside
        front = self.frontside
        left = self.leftside
        if dir == "S":
            self.frontside = up
            self.backside = 7-up
            self.downside = front
            self.upside = 7-front
			
        elif dir == "N":
            self.frontside = 7-up
            self.backside = up
            self.downside = 7-front
            self.upside = front
 		
        elif dir == "E":
            self.rightside = up
            self.leftside = 7-up
            self.upside = left
            self.downside = 7-left
		
        elif dir == "W":
            self.rightside = 7-up
            self.leftside = up
            self.upside = 7-left
            self.downside = left
	
    def getUpside(self):
        return self.upside
		
n = list(map(int,input().split()))
com = list(input())

dice = Dice()
for i in range(len(com)):
    dice.throwDice(com[i])

print(n[dice.getUpside()-1])

Submission status: Accepted

Solution code:
dice = map(int, raw_input().split())
inst = raw_input()

for i in range(len(inst)):
    if inst[i] == 'E':
        temp = dice[5]
        dice[5] = dice[2]
        dice[2] = dice[0]
        dice[0] = dice[3]
        dice[3] = temp
    elif inst[i] == 'W':
        temp = dice[5]
        dice[5] = dice[3]
        dice[3] = dice[0]
        dice[0] = dice[2]
        dice[2] = temp
    elif inst[i] == 'N':
        temp = dice[5]
        dice[5] = dice[4]
        dice[4] = dice[0]
        dice[0] = dice[1]
        dice[1] = temp
    elif inst[i] == 'S':
        temp = dice[5]
        dice[5] = dice[1]
        dice[1] = dice[0]
        dice[0] = dice[4]
        dice[4] = temp

print dice[0]

Submission status: Accepted

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

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

 def InsSN(self, one, two, five, six):
  self.dice[0] = one
  self.dice[1] = two
  self.dice[4] = five
  self.dice[5] = six

 def S(self):
  one = self.dice[4]
  two = self.dice[0]
  five = self.dice[5]
  six = self.dice[1]
  self.InsSN(one, two, five, six)

 def N(self):
  one = self.dice[1]
  two = self.dice[5]
  five = self.dice[0]
  six = self.dice[4]
  self.InsSN(one, two, five, six)
  
 def InsWE(self, one, three, four, six):
  self.dice[0] = one
  self.dice[2] = three
  self.dice[3] = four
  self.dice[5] = six
 
 def W(self):
  one = self.dice[2]
  three = self.dice[5]
  four = self.dice[0]
  six = self.dice[3]
  self.InsWE(one, three, four, six)

 def E(self):
  one = self.dice[3]
  three = self.dice[0]
  four = self.dice[5]
  six = self.dice[2]
  self.InsWE(one, three, four, six)

d = Dice(d)

for i in range(len(O)):
 if O[i] == 'S':
  d.S()
 elif O[i] == 'N':
  d.N()
 elif O[i] == 'E':
  d.E()
 elif O[i] == 'W':
  d.W()

print(d.dice[0])

Submission status: Accepted

Solution code:
dice = map(int, raw_input().split())
inst = raw_input()
 
def rolling(inst, dice):
    if inst == 'E':
        dice[5], dice[2], dice[0], dice[3] = dice[2], dice[0], dice[3], dice[5]
    elif inst == 'W':
        dice[5], dice[3], dice[0], dice[2] = dice[3], dice[0], dice[2], dice[5]
    elif inst == 'N':
        dice[5], dice[4], dice[0], dice[1] = dice[4], dice[0], dice[1], dice[5]
    elif inst == 'S':
        dice[5], dice[1], dice[0], dice[4] = dice[1], dice[0], dice[4], dice[5]
 
for i in range(len(inst)):
    rolling(inst[i], dice)
print dice[0]

Submission status: Accepted

Solution code:
d = list(map(int, input().split()))
order = input()
class Dice():
    def __init__(self, d):
        self.dice = d

    def InsSN(self, one, two, five, six):
        self.dice[0] = one
        self.dice[1] = two
        self.dice[4] = five
        self.dice[5] = six
        
    def InsWE(self, one, three, four, six):
        self.dice[0] = one
        self.dice[2] = three
        self.dice[3] = four
        self.dice[5] = six

    def S(self):
        one = self.dice[4]
        two = self.dice[0]
        five = self.dice[5]
        six = self.dice[1]
        self.InsSN(one, two, five, six)

    def N(self):
        one = self.dice[1]
        two = self.dice[5]
        five = self.dice[0]
        six = self.dice[4]
        self.InsSN(one, two, five, six)
 
    def W(self):
        one = self.dice[2]
        three = self.dice[5]
        four = self.dice[0]
        six = self.dice[3]
        self.InsWE(one, three, four, six)
        
    def E(self):
        one = self.dice[3]
        three = self.dice[0]
        four = self.dice[5]
        six = self.dice[2]
        self.InsWE(one, three, four, six)
        
    def roll(self, order):
        if order == 'S':
            self.S()
        elif order == 'N':
            self.N()
        elif order == 'E':
            self.E()
        elif order == 'W':
            self.W()
d = Dice(d)
for o in order:
    d.roll(o)
print(d.dice[0])

Submission status: Accepted

Solution code:
class Dice(object):
    """Dice Class

    """

    def __init__(self, numbers):
        """

        Args:
            numbers:
        """
        self.numbers = {1: numbers[0], 2: numbers[1], 3: numbers[2], 4: numbers[3], 5: numbers[4], 6: numbers[5]}

        self.vertical = [self.numbers[1], self.numbers[2], self.numbers[6], self.numbers[5]]
        self.horizontal = [self.numbers[4], self.numbers[1], self.numbers[3], self.numbers[6]]

    def move_dice(self, s):
        """

        Args:
            s: move direction

        Returns:

        """
        if s == 'N':
            self.move_north()
        elif s == 'S':
            self.move_south()
        elif s == 'W':
            self.move_west()
        elif s == 'E':
            self.move_east()

    def move_south(self):
        """move this dice towered north
        """
        self.vertical = (self.vertical * 2)[3:7]
        self.horizontal[1] = self.vertical[0]
        self.horizontal[3] = self.vertical[2]

    def move_north(self):
        """move this dice towered south
        """
        self.vertical = (self.vertical * 2)[1:5]
        self.horizontal[1] = self.vertical[0]
        self.horizontal[3] = self.vertical[2]

    def move_east(self):
        """move this dice towered east
        """
        self.horizontal = (self.horizontal * 2)[3:7]
        self.vertical[0] = self.horizontal[1]
        self.vertical[2] = self.horizontal[3]

    def move_west(self):
        """move this dice towered west
        """
        self.horizontal = (self.horizontal * 2)[1:5]
        self.vertical[0] = self.horizontal[1]
        self.vertical[2] = self.horizontal[3]

    def get_top(self):
        return self.vertical[0]


numbers = [int(x) for x in raw_input().split()]
dice1 = Dice(numbers=numbers)
for s in raw_input():
    dice1.move_dice(s)

print(dice1.get_top())

Submission status: Accepted

Solution code:
class Dice(object):
    """
    6??¢???????????????
    ?????¢???top, ?????¢???bottom???????????\??????4??¢??????????????? north, south, east, west ??¨?????¶???
    """
    def __init__(self, faces):
        # faces???????????????????????¨?????????????????????????????????
        # ???????????? top, south, east, west, north, bottom ????????§????´????????????????????????¨??????????????????????????§???top??????????????£????????????
        self.top = faces[0]
        self.south = faces[1]
        self.east = faces[2]
        self.west = faces[3]
        self.north = faces[4]
        self.bottom = faces[5]

    def rotate(self, dir):
        # ???????????????dir??????????????????????????¢?????????
        # ????????????N, S, E, W???????????????????????????(1??????)??§????????????
        if dir == 'N':
            temp = self.top
            self.top = self.south
            self.south = self.bottom
            self.bottom = self.north
            self.north = temp
        elif dir == 'S':
            temp = self.top
            self.top = self.north
            self.north = self.bottom
            self.bottom = self.south
            self.south = temp
        elif dir == 'E':
            temp = self.top
            self.top = self.west
            self.west = self.bottom
            self.bottom = self.east
            self.east = temp
        elif dir == 'W':
            temp = self.top
            self.top = self.east
            self.east = self.bottom
            self.bottom = self.west
            self.west = temp
        # self.print()

    def get_top_value(self):
        return self.top

    def print(self):
        print('=' * 64)
        print('top: {0}'.format(self.top))
        print('south: {0}'.format(self.south))
        print('bottom: {0}'.format(self.bottom))
        print('north: {0}'.format(self.north))
        print('east: {0}'.format(self.east))
        print('west: {0}'.format(self.west))
        print('=' * 64)


if __name__ == '__main__':
    # ??????????????\???
    dice_values = [int(x) for x in input().split(' ')]
    rotations = input()

    # ????????????????????????????????¢?????????
    d = Dice(dice_values)
    for r in rotations:
        d.rotate(r)

    # ?????¢??????????¢????????????????
    print('{0}'.format(d.get_top_value()))

Submission status: Accepted

Solution code:
class Dice:
    def __init__(self):
        self.u=1
        self.w=2
        self.s=3
        self.e=4
        self.n=5
        self.d=6
        self.dic={"W":0,"S":1,"E":2,"N":3}
    
    def __init__(self,u,w,s,e,n,d):
        self.u=u
        self.w=w
        self.s=s
        self.e=e
        self.n=n
        self.d=d
        self.dic={"W":0,"S":1,"E":2,"N":3}

    def rot(self,way):
        if isinstance(way,str):
            way=self.dic[way]

        if(way==0):
            c=self.u
            self.u=self.e
            self.e=self.d
            self.d=self.w
            self.w=c
        elif way==1:
            c=self.u
            self.u=self.n
            self.n=self.d
            self.d=self.s
            self.s=c
        elif way==2:
            c=self.u
            self.u=self.w
            self.w=self.d
            self.d=self.e
            self.e=c
        else :
            c=self.u
            self.u=self.s
            self.s=self.d
            self.d=self.n
            self.n=c

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

Submission status: Accepted

Solution code:
dice = list(map(str, input().split()))
direction = input()
for i in range(len(direction)):
    if direction[i] == "N":
        dice[0], dice[1], dice[4], dice[5] = dice[1], dice[5], dice[0], dice[4]
    elif direction[i] == "S":
        dice[0], dice[1], dice[4], dice[5] = dice[4], dice[0], dice[5], dice[1]
    elif direction[i] == "W":
        dice[0], dice[2], dice[3], dice[5] = dice[2], dice[5], dice[0], dice[3]
    else:
        dice[0], dice[2], dice[3], dice[5] = dice[3], dice[0], dice[5], dice[2]
print(dice[0])

Submission status: Accepted

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

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

	def roll(self,com):
		a1,a2,a3,a4,a5,a6=self.d
		if com=="E":
			self.d = [a4,a2,a1,a6,a5,a3]
		elif com=="W":
			self.d = [a3,a2,a6,a1,a5,a4]
		elif com=="S":
			self.d = [a5,a1,a3,a4,a6,a2]
		elif com=="N":
			self.d = [a2,a6,a3,a4,a1,a5]

dice1=dice(d)	
for com in c:
	dice1.roll(com)
print(dice1.d[0])

Submission status: Accepted

Solution code:
class Dice(object):
    def __init__(self,num):
        self.f=num[0]
        self.s=num[1]
        self.e=num[2]
        self.w=num[3]
        self.n=num[4]
        self.b=num[5]
    def create(self,order):
        if order=='N':
            return [self.s,self.b,self.e,self.w,self.f,self.n]
        elif order=='S':
            return [self.n,self.f,self.e,self.w,self.b,self.s]

        elif order=='E':
            return [self.w,self.s,self.f,self.b,self.n,self.e]
        else:
            return [self.e,self.s,self.b,self.f,self.n,self.w]
    @classmethod
    def Dice_create(cls,num):
            return cls(num)


num=list(map(int,input().split()))
command=input()
dice=Dice(num)
for i in range(len(command)):
    temp=dice.create(command[i])
    dice=Dice.Dice_create(temp)
print(dice.f)

Submission status: Accepted

Solution code:
d = [_ for _ in input().split()]

commands = input()

for c in commands:
  if c == 'E':
    d[0], d[2], d[3], d[5] = d[3], d[0], d[5], d[2]
  elif c == 'W':
    d[0], d[2], d[3], d[5] = d[2], d[5], d[0], d[3]
  elif c == 'N':
    d[0], d[1], d[4], d[5] = d[1], d[5], d[0], d[4]
  elif c == 'S':
    d[0], d[1], d[4], d[5] = d[4], d[0], d[5], d[1]

print(d[0])

Submission status: Accepted

Solution code:
class dice:
  def __init__(self, dice):
    self.d = dice

  def roll(self, c):
    d = self.d
    if c == 'E':
      d[0], d[2], d[3], d[5] = d[3], d[0], d[5], d[2]
    elif c == 'W':
      d[0], d[2], d[3], d[5] = d[2], d[5], d[0], d[3]
    elif c == 'N':
      d[0], d[1], d[4], d[5] = d[1], d[5], d[0], d[4]
    elif c == 'S':
      d[0], d[1], d[4], d[5] = d[4], d[0], d[5], d[1]
    self.d = d
  def print(self):
    print(self.d[0])

d = dice([_ for _ in input().split()])

commands = input()
for c in commands:
  d.roll(c)
d.print()

Submission status: Accepted

Solution code:
label = input().split()
rot = input()

dice = {
        "top":1,
        "front":2,
        "right":3,
        "left":4,
        "back":5,
        "bottom":6
        }

for r in rot:
    if r == 'E':
        t = dice["top"]
        dice["top"] = dice["left"]
        dice["left"] = dice["bottom"]
        dice["bottom"] = dice["right"]
        dice["right"] = t
    elif r == 'N':
        t = dice["top"]
        dice["top"] = dice["front"]
        dice["front"] = dice["bottom"]
        dice["bottom"] = dice["back"]
        dice["back"] = t
    elif r == 'S':
        t = dice["top"]
        dice["top"] = dice["back"]
        dice["back"] = dice["bottom"]
        dice["bottom"] = dice["front"]
        dice["front"] = t
    elif r == 'W':
        t = dice["top"]
        dice["top"] = dice["right"]
        dice["right"] = dice["bottom"]
        dice["bottom"] = dice["left"]
        dice["left"] = t
print(label[dice["top"]-1])

Submission status: Accepted

Solution code:
label = input().split()
rot = input()
 
dice = {
        "top":1,
        "front":2,
        "right":3,
        "left":4,
        "back":5,
        "bottom":6
        }
 
for r in rot:
    if r == 'E':
        dice["top"], dice["left"], dice["bottom"], dice["right"] = \
        dice["left"], dice["bottom"], dice["right"], dice["top"]
    elif r == 'N':
        dice["top"], dice["front"], dice["bottom"], dice["back"] = \
        dice["front"], dice["bottom"], dice["back"], dice["top"]
    elif r == 'S':
        dice["top"], dice["back"], dice["bottom"], dice["front"] = \
        dice["back"], dice["bottom"], dice["front"], dice["top"]
    elif r == 'W':
        dice["top"], dice["right"], dice["bottom"], dice["left"] = \
        dice["right"], dice["bottom"], dice["left"], dice["top"]
print(label[dice["top"]-1])

Submission status: Accepted

Solution code:

class Dice:
    def __init__(self, label):
        self.d = label

    def roll(self, direction):
        if direction == "N":
            self.d[0], self.d[1], self.d[5], self.d[4] = self.d[1], self.d[5], self.d[4], self.d[0]
        elif direction == "S":
            self.d[0], self.d[1], self.d[5], self.d[4] = self.d[4], self.d[0], self.d[1], self.d[5]
        elif direction == "E":
            self.d[0], self.d[2], self.d[5], self.d[3] = self.d[3], self.d[0], self.d[2], self.d[5]
        else:
            self.d[0], self.d[2], self.d[5], self.d[3] = self.d[2], self.d[5], self.d[3], self.d[0]

label = [int(i) for i in input().split()]
cmd = input()

dice1 = Dice(label)

for i in cmd:
    dice1.roll(i)

print(dice1.d[0])

Submission status: Accepted

Solution code:
op = {'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)}
f = input().split()
for i in input():
    f = [f[j] for j in op[i]]
print(f[0])

Submission status: Accepted

Solution code:
n = [int(i) for i in input().split()]
s = input()


class Dice(object):
    def __init__(self,num):
        self.n = num[4]
        self.e = num[2]
        self.w = num[3]
        self.s = num[1]
        self.center = num[0]
        self.back = num[5]

    def move(self,str):
        if str == 'N':
            x = self.n
            self.n = self.center
            self.center = self.s
            self.s = self.back
            self.back = x
            return self.center
        elif str == 'S':
            x = self.s
            self.s = self.center
            self.center = self.n
            self.n = self.back
            self.back = x
            return self.center
        elif str== 'E':
            x = self.e
            self.e = self.center
            self.center = self.w
            self.w = self.back
            self.back = x
            return self.center
        elif str == 'W':
            x = self.w
            self.w = self.center
            self.center = self.e
            self.e = self.back
            self.back = x
            return self.center

dice = Dice(n)
status = 0

for i in range(len(s)):
    status = dice.move(s[i])

print(status)

Submission status: Accepted

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

    def throw(self, direction):
        if direction == "E":
            pmen = men[:]
            men[0] = pmen[3]
            men[1] = pmen[1]
            men[2] = pmen[0]
            men[3] = pmen[5]
            men[4] = pmen[4]
            men[5] = pmen[2]
        elif direction == "W":
            pmen = men[:]
            men[0] = pmen[2]
            men[1] = pmen[1]
            men[2] = pmen[5]
            men[3] = pmen[0]
            men[4] = pmen[4]
            men[5] = pmen[3]
        elif direction == "S":
            pmen = men[:]
            men[0] = pmen[4]
            men[1] = pmen[0]
            men[2] = pmen[2]
            men[3] = pmen[3]
            men[4] = pmen[5]
            men[5] = pmen[1]
        elif direction == "N":
            pmen = men[:]
            men[0] = pmen[1]
            men[1] = pmen[5]
            men[2] = pmen[2]
            men[3] = pmen[3]
            men[4] = pmen[0]
            men[5] = pmen[4]


    def printUe(self):
        print (self.men)[0]

    def printMen(self):
        print self.men

men = map(int, (raw_input()).split(" "))
d = Dice(men)

S = raw_input()
for s in S:
    d.throw(s)
d.printUe()

Submission status: Accepted

Solution code:
class Dice:

    __top = 0
    __front = 1
    __right = 2
    __left = 3
    __back = 4
    __bottom = 5

    def __init__(self, a, b, c, d, e, f):
        self.__dice = [a,b,c,d,e,f]

    def S(self):
        dice_before = self.__dice[:]
        self.__dice[Dice.__top]    = dice_before[Dice.__back]
        self.__dice[Dice.__front]  = dice_before[Dice.__top]
        self.__dice[Dice.__right]  = dice_before[Dice.__right]
        self.__dice[Dice.__left]   = dice_before[Dice.__left]
        self.__dice[Dice.__back]   = dice_before[Dice.__bottom]
        self.__dice[Dice.__bottom] = dice_before[Dice.__front]

    def E(self):
        dice_before = self.__dice[:]
        self.__dice[Dice.__top]    = dice_before[Dice.__left]
        self.__dice[Dice.__front]  = dice_before[Dice.__front]
        self.__dice[Dice.__right]  = dice_before[Dice.__top]
        self.__dice[Dice.__left]   = dice_before[Dice.__bottom]
        self.__dice[Dice.__back]   = dice_before[Dice.__back]
        self.__dice[Dice.__bottom] = dice_before[Dice.__right]

    def W(self):
        dice_before = self.__dice[:]
        self.__dice[Dice.__top]    = dice_before[Dice.__right]
        self.__dice[Dice.__front]  = dice_before[Dice.__front]
        self.__dice[Dice.__right]  = dice_before[Dice.__bottom]
        self.__dice[Dice.__left]   = dice_before[Dice.__top]
        self.__dice[Dice.__back]   = dice_before[Dice.__back]
        self.__dice[Dice.__bottom] = dice_before[Dice.__left]

    def N(self):
        dice_before = self.__dice[:]
        self.__dice[Dice.__top]    = dice_before[Dice.__front]
        self.__dice[Dice.__front]  = dice_before[Dice.__bottom]
        self.__dice[Dice.__right]  = dice_before[Dice.__right]
        self.__dice[Dice.__left]   = dice_before[Dice.__left]
        self.__dice[Dice.__back]   = dice_before[Dice.__top]
        self.__dice[Dice.__bottom] = dice_before[Dice.__back]

    def top(self):
        return(self.__dice[Dice.__top])

a,b,c,d,e,f = input().split()
dice = Dice(a,b,c,d,e,f)
com = input()
for i in com:
    if i == 'S':
        dice.S()

    elif i == 'E':
        dice.E()

    elif i == 'W':
        dice.W()

    elif i == 'N':
        dice.N()

print(dice.top())