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:
class Dice:
    def __init__(self,l):
        self.l = l
    
    def N(self):
        self.l[0], self.l[4], self.l[5], self.l[1] = self.l[1], self.l[0], self.l[4], self.l[5]
        
    def S(self):
        self.l[0], self.l[1], self.l[5], self.l[4] = self.l[4], self.l[0], self.l[1], self.l[5]
    
    def W(self):
        self.l[0], self.l[3], self.l[5], self.l[2] = self.l[2], self.l[0], self.l[3], self.l[5]
        
    def E(self):
        self.l[0], self.l[2], self.l[5], self.l[3] = self.l[3], self.l[0], self.l[2], self.l[5]
    
    def number(self, i):
        return self.l[i - 1]
    
        
dice = Dice(list(map(int, input().split())))
s = list(input())

for i in s:
    if i == "N":
        dice.N()
    elif i == "S":
        dice.S()
    elif i == "W":
        dice.W()
    elif i == "E":
        dice.E()
print(dice.number(1))

Submission status: Accepted

Solution code:
class Dice():

    def __init__(self, *n):
       self.rolls = n

    def spin(self, order):
        if order == "N":
            self.rolls = [
                self.rolls[1],
                self.rolls[5],
                self.rolls[2],
                self.rolls[3],
                self.rolls[0],
                self.rolls[4]
            ]
        if order == "E":
            self.rolls = [
                self.rolls[3],
                self.rolls[1],
                self.rolls[0],
                self.rolls[5],
                self.rolls[4],
                self.rolls[2]
            ]
        if order == "S":
            self.rolls = [
                self.rolls[4],
                self.rolls[0],
                self.rolls[2],
                self.rolls[3],
                self.rolls[5],
                self.rolls[1]
            ]
        if order == "W":
            self.rolls = [
                self.rolls[2],
                self.rolls[1],
                self.rolls[5],
                self.rolls[0],
                self.rolls[4],
                self.rolls[3]
            ]
        return self.rolls[0]


d = Dice(*[int(i) for i in input().split()])
for order in list(input()):
    l = d.spin(order)
print(l)

Submission status: Accepted

Solution code:
dice = list(map(int, input().split()))
directions = input()

for direction in directions:
    if direction == 'N':
        dice = [dice[1], dice[5], dice[2], dice[3], dice[0], dice[4]]
    elif direction == 'S':
        dice = [dice[4], dice[0], dice[2], dice[3], dice[5], dice[1]]
    elif direction == 'W':
        dice = [dice[2], dice[1], dice[5], dice[0], dice[4], dice[3]]
    else:
        dice = [dice[3], dice[1], dice[0], dice[5], dice[4], dice[2]]

print(dice[0])

Submission status: Accepted

Solution code:
dice = list(map(int, input().split()))
cmd = input()

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

for s in cmd:
    dice = [dice[x] for x in mask[s]]

print(dice[0])

Submission status: Accepted

Solution code:
class dice:
    men = [0] * 7
    def __init__(self, li):
        self.men = [0] + li
    def move(self, h):
        if h == "N":
            t = self.men[1]
            self.men[1] = self.men[2]
            self.men[2] = self.men[6]
            self.men[6] = self.men[5]
            self.men[5] = t
        elif h == "S":
            t = self.men[1]
            self.men[1] = self.men[5]
            self.men[5] = self.men[6]
            self.men[6] = self.men[2]
            self.men[2] = t
        elif h == "W":
            t = self.men[1]
            self.men[1] = self.men[3]
            self.men[3] = self.men[6]
            self.men[6] = self.men[4]
            self.men[4] = t
        elif h == "E":
            t = self.men[1]
            self.men[1] = self.men[4]
            self.men[4] = self.men[6]
            self.men[6] = self.men[3]
            self.men[3] = t
saikoro = dice(list(map(int, input().split())))
for s in input():
    saikoro.move(s)
print(saikoro.men[1])

Submission status: Accepted

Solution code:
a, b, c, d, e, f = map(int, input().split())
S = list(input())
i = 0
number1 = a
number2 = b
number3 = c
number4 = d
number5 = e
number6 = f

while i < len(S) :
    if S[i] == "N" :
        number1 = b
        number2 = f
        number3 = c
        number4 = d
        number5 = a
        number6 = e
    elif S[i] == "S" :
        number1 = e
        number2 = a
        number3 = c
        number4 = d
        number5 = f
        number6 = b
    elif S[i] == "E" :
        number1 = d
        number2 = b
        number3 = a
        number4 = f
        number5 = e
        number6 = c
    elif S[i] == "W" :
        number1 = c
        number2 = b
        number3 = f
        number4 = a
        number5 = e
        number6 = d
    a = number1
    b = number2
    c = number3
    d = number4
    e = number5
    f = number6
    i = i + 1
print(number1)

Submission status: Accepted

Solution code:
d=input().split()
for o in list(input()):
 s={'N':(0,1,5,4),'W':(0,2,5,3),'E':(0,3,5,2),'S':(0,4,5,1)}[o]
 for i in range(3):d[s[i+1]],d[s[i]]=d[s[i]],d[s[i+1]]
print(d[0])

Submission status: Accepted

Solution code:
d=input().split()
for o in input():
 s={'N':(0,1,5,4),'W':(0,2,5,3),'E':(0,3,5,2),'S':(0,4,5,1)}[o]
 for i in range(3):d[s[i+1]],d[s[i]]=d[s[i]],d[s[i+1]]
print(d[0])

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
d=input().split()
s={'N':"152304",'W':"215043",'E':"310542",'S':"402351"}
for o in input():
 d=[d[int(i)]for i in s[o]]
print(d[0])

Submission status: Accepted

Solution code:
dice = input().split()
direction = list(input())
dice2 = []
for i in range(len(direction)):
    dice2 = dice
    if direction[i] == 'E':
        dice = [dice2[3],dice2[1],dice2[0],dice2[5],dice2[4],dice2[2]]
    elif direction[i] == 'N':
        dice = [dice2[1],dice2[5],dice2[2],dice2[3],dice2[0],dice2[4]]
    elif direction[i] == 'S':
        dice = [dice2[4],dice2[0],dice2[2],dice2[3],dice2[5],dice2[1]]
    else:
        dice = [dice2[2],dice2[1],dice2[5],dice2[0],dice2[4],dice2[3]]
print('{0}'.format(int(dice[0])))

Submission status: Accepted

Solution code:
class dice:

    def __init__(self, numlist):
        self._men = {"T": numlist[0],
                     "B": numlist[5],
                     "N": numlist[4],
                     "S": numlist[1],
                     "W": numlist[3],
                     "E": numlist[2]}

    def roll(self, direction):
        t = dict(self._men)

        if direction == "N":
            self._men["T"] = t["S"]
            self._men["B"] = t["N"]
            self._men["N"] = t["T"]
            self._men["S"] = t["B"]
        elif direction == "S":
            self._men["T"] = t["N"]
            self._men["B"] = t["S"]
            self._men["S"] = t["T"]
            self._men["N"] = t["B"]
        elif direction == "W":
            self._men["T"] = t["E"]
            self._men["B"] = t["W"]
            self._men["W"] = t["T"]
            self._men["E"] = t["B"]
        elif direction == "E":
            self._men["T"] = t["W"]
            self._men["B"] = t["E"]
            self._men["W"] = t["B"]
            self._men["E"] = t["T"]


    def gettop(self):
        return self._men["T"]

def decode():
    numlist = [int(x) for x in input().split()]
    dlist = input()
    return numlist, dlist

if __name__ == '__main__':

    numlist, dlist = decode()
    d1 = dice(numlist)
    for c in dlist:
        d1.roll(c)
    print(d1.gettop())

Submission status: Accepted

Solution code:
class Dice:
    def __init__(self, hoge):
        self.num = hoge
        self.face = {'U': 0, 'W': 3, 'E': 2, 'N': 4, 'S': 1, 'B': 5} 
    
    def move(self, direct):
        previouse = {k: v for k, v in self.face.items()}
        if direct == 'E':
            self.face['U'] = previouse['W']
            self.face['W'] = previouse['B']
            self.face['E'] = previouse['U']
            self.face['B'] = previouse['E']
        elif direct == 'W':
            self.face['U'] = previouse['E']
            self.face['W'] = previouse['U']
            self.face['E'] = previouse['B']
            self.face['B'] = previouse['W']
        elif direct == 'N':
            self.face['U'] = previouse['S']
            self.face['N'] = previouse['U']
            self.face['S'] = previouse['B']
            self.face['B'] = previouse['N']
        elif direct == 'S':
            self.face['U'] = previouse['N']
            self.face['N'] = previouse['B']
            self.face['S'] = previouse['U']
            self.face['B'] = previouse['S']
    
    def get_upper(self):
        return self.num[self.face['U']]
        
if __name__ == '__main__':
    dice = Dice([int(x) for x in input().split()])
    for d in input():
        dice.move(d)
    print (dice.get_upper())

Submission status: Accepted

Solution code:
# coding:utf-8
class Dice:
    def __init__(self):
        self.f = [0 for i in range(6)]
    def roll_z(self): self.roll(1,2,4,3)
    def roll_y(self): self.roll(0,2,5,3)
    def roll_x(self): self.roll(0,1,5,4)
    def roll(self,i,j,k,l):
        t = self.f[i]; self.f[i] = self.f[j]; self.f[j] = self.f[k]; self.f[k] = self.f[l]; self.f[l] = t
    def move(self,ch):
        if ch == 'E':
            for i in range(3):
                self.roll_y()
        if ch == 'W':
            self.roll_y()
        if ch == 'N':
            self.roll_x()
        if ch == 'S':
            for i in range(3):
                self.roll_x()
dice = Dice()
dice.f = map(int, raw_input().split())
com = raw_input()
for i in range(len(com)):
    dice.move(com[i])
print dice.f[0]

Submission status: Accepted

Solution code:
class Dice:
    def __init__(self):
        self.top = 1
        self.dside = 2
        self.rside = 3
        self.lside = 4
        self.uside = 5
        self.bottom = 6
    def north(self):
        (self.top, self.dside, self.bottom, self.uside) = (self.dside, 
            self.bottom, self.uside, self.top)
    def east(self):
        (self.top, self.lside, self.bottom, self.rside) = (self.lside,
            self.bottom, self.rside, self.top)
    def south(self):
        (self.top, self.dside, self.bottom, self.uside) = (self.uside, 
            self.top, self.dside, self.bottom)
    def west(self):
        (self.top, self.lside, self.bottom, self.rside) = (self.rside,
            self.top, self.lside, self.bottom)

num, dice = list(map(int, input().split())), Dice()
label = {i+1:num[i] for i in range(6)}
com = [i for i in input()]
for i in com:
    if i=="N":
        dice.north()
    elif i=="E":
        dice.east()
    elif i=="S":
        dice.south()
    else:
        dice.west()
print(label[dice.top])

Submission status: Accepted

Solution code:
class Dice:
    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 N(self):
        save = self.top
        self.top = self.front
        self.front = self.bottom
        self.bottom = self.back
        self.back = save

    def E(self):
        save = self.top
        self.top = self.left
        self.left = self.bottom
        self.bottom = self.right
        self.right = save

    def S(self):
        save = self.top
        self.top = self.back
        self.back = self.bottom
        self.bottom = self.front
        self.front = save

    def W(self):
        save = self.top
        self.top = self.right
        self.right = self.bottom
        self.bottom = self.left
        self.left = save

    def display(self):
        print(self.top)

nums = list(map(int, input().split()))
dice = Dice(nums[0], nums[1], nums[2], nums[3], nums[4], nums[5])
s = input()
for c in s:
    if c == 'N':
        dice.N()
    elif c == 'E':
        dice.E()
    elif c == 'S':
        dice.S()
    elif c == 'W':
        dice.W()
dice.display()

Submission status: Accepted

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

    def korokoro(self,com):
        if com == 'E':
            self.number = [self.number[i] for i in [3,1,0,5,4,2]]
        if com == 'S':
            self.number = [self.number[i] for i in [4,0,2,3,5,1]]
        if com == 'N':
            self.number = [self.number[i] for i in [1,5,2,3,0,4]]
        if com == 'W':
            self.number = [self.number[i] for i in [2,1,5,0,4,3]]
i_number = [int(x) for x in input().split()]
com_list = input()
d = dice(i_number)
for c in com_list:
    d.korokoro(c)
print(d.number[0])

Submission status: Accepted

Solution code:
class Dice:
    def __init__(self, dice):
        self.dice = dice
        self.buff = [n for n in dice]
    def east(self):
        self.dice[0] = self.buff[3]
        self.dice[2] = self.buff[0]
        self.dice[5] = self.buff[2]
        self.dice[3] = self.buff[5]
        self.buff = [n for n in self.dice]
    def west(self):
        self.dice[0] = self.buff[2]
        self.dice[2] = self.buff[5]
        self.dice[5] = self.buff[3]
        self.dice[3] = self.buff[0]
        self.buff = [n for n in self.dice]
    def north(self):
        self.dice[0] = self.buff[1]
        self.dice[1] = self.buff[5]
        self.dice[5] = self.buff[4]
        self.dice[4] = self.buff[0]
        self.buff = [n for n in self.dice]
    def south(self):
        self.dice[0] = self.buff[4]
        self.dice[1] = self.buff[0]
        self.dice[5] = self.buff[1]
        self.dice[4] = self.buff[5]
        self.buff = [n for n in self.dice]

nums = list(map(int, input().split()))
d = Dice(nums)
way = input()

for w in way:
    if w == "E":
        d.east()
    if w == "W":
        d.west()
    if w == "N":
        d.north()
    if w == "S":
        d.south()

print(d.dice[0])

Submission status: Accepted

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

def rotate_n(p):
    temp = p['top']
    p['top'] = p['south']
    p['south'] = p['bot']
    p['bot'] = p['north']
    p['north'] = temp

def rotate_s(p):
    temp = p['top']
    p['top'] = p['north']
    p['north'] = p['bot']
    p['bot'] = p['south']
    p['south'] = temp

def rotate_e(p):
    temp = p['top']
    p['top'] = p['west']
    p['west'] = p['bot']
    p['bot'] = p['east']
    p['east'] = temp

def rotate_w(p):
    temp = p['top']
    p['top'] = p['east']
    p['east'] = p['bot']
    p['bot'] = p['west']
    p['west'] = temp

import sys

face = sys.stdin.readline().split()
command = sys.stdin.readline().strip()

position = {'top':face[0], 'bot':face[5], 'east':face[2],
            'west':face[3], 'south':face[1], 'north': face[4]}

for roll in command:
    if roll == 'N':
        rotate_n(position)
    elif roll == 'S':
        rotate_s(position)
    elif roll == 'E':
        rotate_e(position)
    elif roll == 'W':
        rotate_w(position)
    else:
        raise ValueError

print(position['top'])

Submission status: Accepted

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

Submission status: Accepted

Solution code:
from collections import deque

class Dice:
    def __init__(self, top, down, right, left, up, bottom):
        self.top = top
        self.bottom = bottom
        self.up = up
        self.down = down
        self.left = left
        self.right = right

    def roll(self, command):
        for c in list(command):
            if c == 'N':
                self.up, self.top, self.down, self.bottom = self.top, self.down, self.bottom, self.up
            elif c == 'S':
                self.up, self.top, self.down, self.bottom = self.bottom, self.up, self.top, self.down
            elif c == 'E':
                self.left, self.top, self.right, self.bottom = self.bottom, self.left, self.top, self.right
            elif c == 'W':
                self.left, self.top, self.right, self.bottom = self.top, self.right, self.bottom, self.left

    def pip(self):
        return self.top

if __name__ == '__main__':
    seq = list(map(int, input().split()))
    dice = Dice(*seq)
    dice.roll(input())
    print(dice.pip())

Submission status: Accepted

Solution code:
roll = {"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)}
dice = input().split()
for direction in input():
    dice = [dice[i] for i in roll[direction]]
print(dice[0])

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(' ')))
s = input()
L = [0,1,2]
for i in s:
    if i == 'E':
        a = 5 - L[2]
        b = L[1]
        c = L[0]
        L = [a, b, c]
    elif i == 'W':
        a = L[2]
        b = L[1]
        c = 5 - L[0]
        L = [a, b, c]
    elif i == 'N':
        a = L[1]
        b = 5 - L[0]
        c = L[2]
        L = [a, b, c]
    elif i == 'S':
        a = 5 - L[1]
        b = L[0]
        c = L[2]
        L = [a, b, c]
print(d[L[0]])

Submission status: Accepted

Solution code:
class Dice:
    """サイコロを操作するクラス"""
    def __init__(self, num):
        self.num = num
    def roll_north(self):
        tmp = self.num[:]
        self.num[0] = tmp[1]
        self.num[1] = tmp[5]
        self.num[4] = tmp[0]
        self.num[5] = tmp[4]
    def roll_south(self):
        tmp = self.num[:]
        self.num[0] = tmp[4]
        self.num[1] = tmp[0]
        self.num[4] = tmp[5]
        self.num[5] = tmp[1]
    def roll_east(self):
        tmp = self.num[:]
        self.num[0] = tmp[3]
        self.num[2] = tmp[0]
        self.num[3] = tmp[5]
        self.num[5] = tmp[2]
    def roll_west(self):
        tmp = self.num[:]
        self.num[0] = tmp[2]
        self.num[2] = tmp[5]
        self.num[3] = tmp[0]
        self.num[5] = tmp[3]
    def print_dice(self):
        print(self.num)
    def print_top(self):
        print(self.num[0])

num = list(map(int, input().split()))
dice = Dice(num)
for i in input():
    if i == "N":
        dice.roll_north()
    elif i == "S":
        dice.roll_south()
    elif i == "E":
        dice.roll_east()
    elif i == "W":
        dice.roll_west()
    else:
        print("input error")
dice.print_top()

Submission status: Accepted

Solution code:
from enum import IntEnum


class Direction(IntEnum):
    NORTH = 0
    EAST = 1
    SOUTH = 2
    WEST = 3


class Dice:
    """Dice class implements the structure of a dice
    having six faces.
    """
    def __init__(self, v1, v2, v3, v4, v5, v6):
        self.top = 1
        self.heading = Direction.NORTH
        self.values = [v1, v2, v3, v4, v5, v6]

    def to_dice_axis(self, d):
        return (d - self.heading) % 4

    def to_plain_axis(self, d):
        return (self.heading + d) % 4

    def roll(self, d):
        faces = [[(2, Direction.NORTH), (6, Direction.NORTH),
                  (6, Direction.WEST), (6, Direction.EAST),
                  (6, Direction.SOUTH), (5, Direction.SOUTH)],
                 [(4, Direction.EAST), (4, Direction.NORTH),
                  (2, Direction.NORTH), (5, Direction.NORTH),
                  (3, Direction.NORTH), (4, Direction.WEST)],
                 [(5, Direction.SOUTH), (1, Direction.NORTH),
                  (1, Direction.EAST), (1, Direction.WEST),
                  (1, Direction.SOUTH), (2, Direction.NORTH)],
                 [(3, Direction.WEST), (3, Direction.NORTH),
                  (5, Direction.NORTH), (2, Direction.NORTH),
                  (4, Direction.NORTH), (3, Direction.EAST)]]
        f, nd = faces[self.to_dice_axis(d)][self.top-1]
        self.top = f
        self.heading = self.to_plain_axis(nd)

    def value(self):
        return self.values[self.top-1]


def run():
    values = [int(v) for v in input().split()]
    dice = Dice(*values)
    for d in input():
        if d == 'N':
            dice.roll(Direction.NORTH)
        if d == 'E':
            dice.roll(Direction.EAST)
        if d == 'S':
            dice.roll(Direction.SOUTH)
        if d == 'W':
            dice.roll(Direction.WEST)

    print(dice.value())


if __name__ == '__main__':
    run()

Submission status: Accepted

Solution code:
#coding: utf-8

face = {'N':(1, 5, 2, 3, 0, 4), 'E':(3, 1, 0, 5, 4, 2), 'W':(2, 1, 5, 0, 4, 3), 'S':(4, 0, 2, 3, 5, 1)}
dice = input().split()

for o in input():
    dice = [dice[i] for i in face[o]]

print(dice[0])

Submission status: Accepted

Solution code:
l = list(map(int, input().split()))
s = input()
for c in s:
  if c == "S":
    l = [l[4], l[0], l[2], l[3], l[5], l[1]]
  elif c == "N":
    l = [l[1], l[5], l[2], l[3], l[0], l[4]]
  elif c == "E":
    l = [l[3], l[1], l[0], l[5], l[4], l[2]]
  else:
    l = [l[2], l[1], l[5], l[0], l[4], l[3]]
print(l[0])

Submission status: Accepted

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

Submission status: Accepted

Solution code:
class Dice1():
    def move(self,direction,n):
        if direction == "S":
            top = n[0]
            n[0] = n[4]
            n[4] = n[5]
            n[5] = n[1]
            n[1] = top
        elif direction == "N":
            top = n[0]
            n[0] = n[1]
            n[1] = n[5]
            n[5] = n[4]
            n[4] = top
        elif direction == "E":
            top = n[0]
            n[0] = n[3]
            n[3] = n[5]
            n[5] = n[2]
            n[2] = top
        elif direction == "W":
            top = n[0]
            n[0] = n[2]
            n[2] = n[5]
            n[5] = n[3]
            n[3] = top
        return n
n = [int(i) for i in input().split()]
di = list(input())
dc = Dice1()
for i in di:
    n = dc.move(i,n)
print(n[0])

Submission status: Accepted

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

Submission status: Accepted

Solution code:
class Dice:
    def __init__(self, d):
        self.dice = d
        self.top = d[0]
        self.north = d[4]
        self.west = d[3]
        self.south = d[1]
        self.east = d[2]
        self.bottom = d[5]

    def move(self, d):
        if d == "N":
            self.move_north()
        elif d == "W":
            self.move_west()
        elif d == "S":
            self.move_south()
        elif d == "E":
            self.move_east()

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

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

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

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

if __name__ == "__main__":
    import re

    nums = [int(n) for n in re.split(r"\s+", input().strip())]
    dice = Dice(nums)

    for d in list(input().strip()):
        dice.move(d)

    print(dice.top)

Submission status: Accepted

Solution code:
class Dice:
    def __init__(self, labels):
        self._top = labels[0]
        self._front = labels[1]
        self._right = labels[2]
        self._left = labels[3]
        self._back = labels[4]
        self._bottom = labels[5]
    
    def top(self):
        return self._top
    
    def front(self):
        return self._front
    
    def right(self):
        return self._right
    
    def left(self):
        return self._left
    
    def back(self):
        return self._back
    
    def bottom(self):
        return self._bottom
    
    def role(self, directions):
        for d in directions:
            self._role1(d)
    
    def _role1(self, d):
        if d == "N":
            self._top, self._front, self._bottom, self._back = \
            self._front, self._bottom, self._back, self._top
        elif d == "E":
            self._top, self._left, self._bottom, self._right = \
            self._left, self._bottom, self._right, self._top
        elif d == "S":
            self._top, self._back, self._bottom, self._front = \
            self._back, self._bottom, self._front, self._top
        else:
            self._top, self._right, self._bottom, self._left = \
            self._right, self._bottom, self._left, self._top


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

dice = Dice(xs)
dice.role(directions)

print(dice.top())

Submission status: Accepted

Solution code:
def north(list):
    List = []
    List.append(list[1])
    List.append(list[5])
    List.append(list[2])
    List.append(list[3])
    List.append(list[0])
    List.append(list[4])
    return List

def west(list):
    List = []
    List.append(list[2])
    List.append(list[1])
    List.append(list[5])
    List.append(list[0])
    List.append(list[4])
    List.append(list[3])
    return List
    
def south(list):
    List = []
    List.append(list[4])
    List.append(list[0])
    List.append(list[2])
    List.append(list[3])
    List.append(list[5])
    List.append(list[1])
    return List

def east(list):
    List = []
    List.append(list[3])
    List.append(list[1])
    List.append(list[0])
    List.append(list[5])
    List.append(list[4])
    List.append(list[2])
    return List

dice = list(map(int, input().split()))
x = str(input())
y = list(x)
for i in range(len(x)):
    if y[i] == 'N':
        dice[0:5] = north(dice)
    elif y[i] == 'W':
        dice[0:5] = west(dice)
    elif y[i] == 'S':
        dice[0:5] = south(dice)
    elif y[i] == 'E':
        dice[0:5] = east(dice)
print(dice[0])

Submission status: Accepted

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


class Dice(object):
    def __init__(self, one, two, thr, fou, fiv, six):
        self._one = one
        self._two = two
        self._thr = thr
        self._fou = fou
        self._fiv = fiv
        self._six = six

    def roll(self, direction):
        if direction == "W":
            dice = self._roll_west()
        elif direction == "N":
            dice = self._roll_noth()
        elif direction == "E":
            dice = self._roll_east()
        elif direction == "S":
            dice = self._roll_south()
        else:
            raise ValueError

        return dice

    def _roll_west(self):
        return Dice(self._thr, self._two, self._six,
                    self._one, self._fiv, self._fou)

    def _roll_noth(self):
        return Dice(self._two, self._six, self._thr,
                    self._fou, self._one, self._fiv)

    def _roll_east(self):
        return Dice(self._fou, self._two, self._one,
                    self._six, self._fiv, self._thr)

    def _roll_south(self):
        return Dice(self._fiv, self._one, self._thr,
                    self._fou, self._six, self._two)

    def get_sides(self):
        return [self._one, self._two, self._thr,
                self._fou, self._fiv, self._six]


if __name__ == "__main__":
    args = [int(n) for n in input().split()]
    dice = Dice(*args)
    for dire in input():
        dice = dice.roll(dire)

    print(dice.get_sides()[0])

Submission status: Accepted

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


class Dice:
    def __init__(self, n):
        self.upper    = n[0]
        self.backward = n[1]
        self.right    = n[2]
        self.left     = n[3]
        self.ahead    = n[4]
        self.bottom   = n[5]

    def roll_north(self):
        self.upper, self.ahead, self.bottom, self.backward = self.backward, self.upper, self.ahead, self.bottom

    def roll_south(self):
        self.upper, self.ahead, self.bottom, self.backward = self.ahead, self.bottom, self.backward, self.upper

    def roll_east(self):
        self.upper, self.right, self.bottom, self.left = self.left, self.upper, self.right, self.bottom

    def roll_west(self):
        self.upper, self.right, self.bottom, self.left = self.right, self.bottom, self.left, self.upper


dice_info = Dice(list(map(int, input().split())))
order = list(input())

for i in range(len(order)):
    if 'N' in order[i]:
        dice_info.roll_north()

    elif 'S' in order[i]:
        dice_info.roll_south()

    elif 'E' in order[i]:
        dice_info.roll_east()

    elif'W' in order[i]:
        dice_info.roll_west()

print(dice_info.upper)

Submission status: Accepted

Solution code:
#! python3
# dice_i.py

class dice():
    def __init__(self, arr):
        self.top = arr[0]
        self.south = arr[1]
        self.east = arr[2]
        self.west = arr[3]
        self.north = arr[4]
        self.bottom = arr[5]

    def rotate(self, ope):
        if ope == 'S':
            self.top, self.north, self.bottom, self.south = self.north, self.bottom, self.south, self.top
        elif ope == 'N':
            self.top, self.south, self.bottom, self.north = self.south, self.bottom, self.north, self.top
        elif ope == 'E':
            self.top, self.west, self.bottom, self.east = self.west, self.bottom, self.east, self.top
        elif ope == 'W':
            self.top, self.east, self.bottom, self.west = self.east, self.bottom, self.west, self.top

dc = dice([int(x) for x in input().split(' ')])
opes = list(input())

for op in opes:
    dc.rotate(op)

print(dc.top)