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, f0, f1, f2, f3, f4, f5):
        self.dice_num = [f0, f1, f2, f3, f4, f5]

    def roll_dice(self, command):
        for i in command:
            if i == 'N':
                tmp = self.dice_num[0]
                self.dice_num[0] = self.dice_num[1]
                self.dice_num[1] = self.dice_num[5]
                self.dice_num[5] = self.dice_num[4]
                self.dice_num[4] = tmp

            if i == 'S':
                tmp = self.dice_num[0]
                self.dice_num[0] = self.dice_num[4]
                self.dice_num[4] = self.dice_num[5]
                self.dice_num[5] = self.dice_num[1]
                self.dice_num[1] = tmp

            if i == 'E':
                tmp = self.dice_num[0]
                self.dice_num[0] = self.dice_num[3]
                self.dice_num[3] = self.dice_num[5]
                self.dice_num[5] = self.dice_num[2]
                self.dice_num[2] = tmp

            if i == 'W':
                tmp = self.dice_num[0]
                self.dice_num[0] = self.dice_num[2]
                self.dice_num[2] = self.dice_num[5]
                self.dice_num[5] = self.dice_num[3]
                self.dice_num[3] = tmp

    def print_topface(self):
        print(self.dice_num[0])


if __name__ == "__main__":
    num_list = list(map(int, input().split()))
    command_str = input()
    mydice = dice(*num_list)
    mydice.roll_dice(command_str)
    mydice.print_topface()

Submission status: Accepted

Solution code:
from enum import Enum
import sys
import math

BIG_NUM = 2000000000
MOD = 1000000007
EPS = 0.000000001

#0:中央 1:南 2:東 3:西 4:北 5:裏側
class Dice():

    def __init__(self):
        self.number = [i for i in range(6)]
        self.work = [i for i in range(6)]


    def setNumber(self,n0,n1,n2,n3,n4,n5):
        self.number[0] = n0
        self.number[1] = n1
        self.number[2] = n2
        self.number[3] = n3
        self.number[4] = n4
        self.number[5] = n5


    def roll(self,loc):
        for i in range(6):
            self.work[i] = self.number[i]

        if loc == 'E':
            self.setNumber(self.work[3],self.work[1],self.work[0],self.work[5],self.work[4],self.work[2])
        elif loc == 'N':
            self.setNumber(self.work[1],self.work[5],self.work[2],self.work[3],self.work[0],self.work[4])
        elif loc == 'S':
            self.setNumber(self.work[4],self.work[0],self.work[2],self.work[3],self.work[5],self.work[1])
        elif loc == 'W':
            self.setNumber(self.work[2],self.work[1],self.work[5],self.work[0],self.work[4],self.work[3])


    def get_Top(self):
        return self.number[0]


dice = Dice()
table = list(map(int,input().split()))
dice.setNumber(table[0], table[1], table[2], table[3], table[4], table[5])

loc_array = str(input())
for tmp_loc in loc_array:
    dice.roll(tmp_loc)

print("%d"%(dice.get_Top()))

Submission status: Accepted

Solution code:
# coding: utf-8
# Your code here!

class dice(object):
    def __init__(self, arr):
        self.top = arr[0]
        self.side_s = arr[1]
        self.side_e = arr[2]
        self.side_w = arr[3]
        self.side_n = arr[4]
        self.bottom = arr[5]
    def roll(self, s):
        if s=='S':
            tmp = self.bottom
            self.bottom = self.side_s
            self.side_s = self.top
            self.top = self.side_n
            self.side_n = tmp
        elif s=='E':
            tmp = self.bottom
            self.bottom = self.side_e
            self.side_e = self.top
            self.top = self.side_w
            self.side_w = tmp
        elif s=='W':
            tmp = self.bottom
            self.bottom = self.side_w
            self.side_w = self.top
            self.top = self.side_e
            self.side_e = tmp
        elif s=='N':
            tmp = self.bottom
            self.bottom = self.side_n
            self.side_n = self.top
            self.top = self.side_s
            self.side_s = tmp
    

s = input().split()
# s = '1 2 4 8 16 32'.split()

dice = dice(s)
arr = input()
for a in arr:
    dice.roll(a)
# print(type(dice))
print(dice.top)

Submission status: Accepted

Solution code:
# coding: utf-8
# Your code here!

class Dice:
    def __init__(self,lst):
        self.face=lst
    
    def roll(self,x):
        tmp=self.face
        if x=="E":
            self.face=[tmp[3],tmp[1],tmp[0],tmp[5],tmp[4],tmp[2]]
        if x=="W":
            self.face=[tmp[2],tmp[1],tmp[5],tmp[0],tmp[4],tmp[3]]
        if x=="N":
            self.face=[tmp[1],tmp[5],tmp[2],tmp[3],tmp[0],tmp[4]]
        if x=="S":
            self.face=[tmp[4],tmp[0],tmp[2],tmp[3],tmp[5],tmp[1]]
    
    def showDown(self):
        return self.face[0]
    
dice=Dice(list(map(int,input().split(" "))))
rolling=list(input())
for i in rolling:
    dice.roll(i)
print(dice.showDown())

Submission status: Accepted

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

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

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


(*label,) = map(int, input().split())
dice = Dice(label)
for i in input():
    dice.roll(i)
dice.output_top()

Submission status: Accepted

Solution code:
class Dice:
    def __init__(self, d1, d2, d3, d4, d5, d6):
        self.d1 = d1
        self.d2 = d2
        self.d3 = d3
        self.d4 = d4
        self.d5 = d5
        self.d6 = d6
    def S(self):
        tmp = self.d1
        self.d1 = self.d5
        self.d5 = self.d6
        self.d6 = self.d2
        self.d2 = tmp
    def N(self):
        tmp = self.d1
        self.d1 = self.d2
        self.d2 = self.d6
        self.d6 = self.d5
        self.d5 = tmp
    def E(self):
        tmp = self.d1
        self.d1 = self.d4
        self.d4 = self.d6
        self.d6 = self.d3
        self.d3 = tmp
    def W(self):
        tmp = self.d1
        self.d1 = self.d3
        self.d3 = self.d6
        self.d6 = self.d4
        self.d4 = tmp
    def output(self):
        print(self.d1)

d1, d2, d3, d4, d5, d6 = map(int, input().split())
dice = Dice(d1, d2, d3, d4, d5, d6)
M = input()
for i in range(len(M)):
    if M[i] == 'S':
        dice.S()
    elif M[i] == 'N':
        dice.N()
    elif M[i] == 'E':
        dice.E()
    elif M[i] == 'W':
        dice.W()
dice.output()

Submission status: Accepted

Solution code:
class Dice:
  def __init__(self, list1):
    self.f = list1
  def move(self, direct):
    if direct == "N":
        self.f[0], self.f[1], self.f[4], self.f[5] = self.f[1], self.f[5], self.f[0], self.f[4]
        return self.f
    elif direct == "E":
        self.f[0], self.f[2], self.f[3], self.f[5] = self.f[3], self.f[0], self.f[5], self.f[2]
        return self.f
    elif direct == "S":
         self.f[0], self.f[1], self.f[4], self.f[5] = self.f[4], self.f[0], self.f[5], self.f[1]
         return self.f
    elif direct == "W":
        self.f[0], self.f[2], self.f[3], self.f[5] = self.f[2], self.f[5], self.f[0], self.f[3]
        return self.f

data = list(map(int, input().split()))
direction = input()
dice = Dice(data)
for i in direction:
  dice.move(i)
print(dice.f[0])

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import copy


class Dice:
    def __init__(self, eyes: [int]):
        self.__eyes = eyes

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

    def roll_s(self):
        tmp = copy.copy(self.__eyes)
        tmp[0] = self.__eyes[4]
        tmp[1] = self.__eyes[0]
        tmp[2] = self.__eyes[2]
        tmp[3] = self.__eyes[3]
        tmp[4] = self.__eyes[5]
        tmp[5] = self.__eyes[1]
        self.__eyes = tmp

    def roll_e(self):
        tmp = copy.copy(self.__eyes)
        tmp[0] = self.__eyes[3]
        tmp[1] = self.__eyes[1]
        tmp[2] = self.__eyes[0]
        tmp[3] = self.__eyes[5]
        tmp[4] = self.__eyes[4]
        tmp[5] = self.__eyes[2]
        self.__eyes = tmp

    def roll_n(self):
        tmp = copy.copy(self.__eyes)
        tmp[0] = self.__eyes[1]
        tmp[1] = self.__eyes[5]
        tmp[2] = self.__eyes[2]
        tmp[3] = self.__eyes[3]
        tmp[4] = self.__eyes[0]
        tmp[5] = self.__eyes[4]
        self.__eyes = tmp

    def roll_w(self):
        tmp = copy.copy(self.__eyes)
        tmp[0] = self.__eyes[2]
        tmp[1] = self.__eyes[1]
        tmp[2] = self.__eyes[5]
        tmp[3] = self.__eyes[0]
        tmp[4] = self.__eyes[4]
        tmp[5] = self.__eyes[3]
        self.__eyes = tmp

    def roll(self, direction: str):
        if direction == 'N':
            self.roll_n()
        if direction == 'E':
            self.roll_e()
        if direction == 'S':
            self.roll_s()
        if direction == 'W':
            self.roll_w()


def resolve():
    eyes = list(map(int, input().split()))
    directions = list(input())
    dice = Dice(eyes)
    for direction in directions:
        dice.roll(direction)
    print(dice.top())


resolve()

Submission status: Accepted

Solution code:
dice = [int(i) for i in input().split()]
directions = str(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 == "E":
        dice = [dice[3], dice[1], dice[0], dice[5], dice[4], dice[2]]
    else:
        dice = [dice[2], dice[1], dice[5], dice[0], dice[4], dice[3]]
print(dice[0])

Submission status: Accepted

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

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

d1=Dice(lst)
for direction in directions:
    d1.roll(direction)

print(d1.lst[0])

Submission status: Accepted

Solution code:
class Dice:
    D = {'E':(3,1,0,5,4,2), 'W':(2,1,5,0,4,3), 'S':(4,0,2,3,5,1), 'N':(1,5,2,3,0,4)}
    def __init__(self, tp, fwd, rs, ls, bk, bm):
        self.nbrs = [tp, fwd, rs, ls, bk, bm]
    def rll(self, drctn):
        return [self.nbrs[i] for i in self.D[drctn]]


A = input().split()
for i in input():
    dice = Dice(A[0], A[1], A[2], A[3], A[4], A[5])
    A = dice.rll(i)
print(A[0])

Submission status: Accepted

Solution code:
class Dice:
  arr = []
  tmpArr = []
  def __init__(self, arr):
    self.arr = arr
  def move(self, pos):
    if pos == 'E':
      self.eastMove()
    elif pos == 'N':
      self.northMove()
    elif pos == 'S':
      self.sorthMove()
    elif pos == 'W':
      self.westMove()
  def out(self):
    return self.arr[0]
  def eastMove(self):
    self.changeArr(3, 6)
    self.changeArr(3, 4)
    self.changeArr(3, 1)
  def northMove(self):
    self.changeArr(5, 6)
    self.changeArr(5, 2)
    self.changeArr(5, 1)
  def sorthMove(self):
    self.changeArr(2, 6)
    self.changeArr(2, 5)
    self.changeArr(2, 1)
  def westMove(self):
    self.changeArr(4, 6)
    self.changeArr(4, 3)
    self.changeArr(4, 1)
  def changeArr(self, f, t):
    tmp = self.arr[f - 1]
    self.arr[f - 1] = self.arr[t - 1]
    self.arr[t - 1] = tmp

diceNum = list(map(int, input().split(' ')))
dice = Dice(diceNum)
posAction = input()
for pos in posAction:
  dice.move(pos)
print(dice.out())

Submission status: Accepted

Solution code:
class Dice:
    def __init__(self, a, b, c, d, e, f):
        # サイコロの現在一番上にある面
        self.a = a
        self.b = b
        self.c = c
        self.d = d
        self.e = e
        self.f = f

    def move(self, move_str):
        for i in move_str:
            if i == "N":
                self.move_N()
            elif i == "E":
                self.move_E()
            elif i == "W":
                self.move_W()
            elif i == "S":
                self.move_S()

    def move_N(self):
        tmp1 = self.a
        tmp2 = self.e
        self.a = self.b
        self.b = self.f
        self.e = tmp1
        self.f = tmp2

    def move_E(self):
        tmp1 = self.a
        tmp2 = self.c
        self.a = self.d
        self.c = tmp1
        self.d = self.f
        self.f = tmp2

    def move_W(self):
        tmp1 = self.a
        tmp2 = self.d
        self.a = self.c
        self.c = self.f
        self.d = tmp1
        self.f = tmp2

    def move_S(self):
        tmp1 = self.a
        tmp2 = self.b
        self.a = self.e
        self.b = tmp1
        self.e = self.f
        self.f = tmp2
    """
    def debug(self):
        print("--------")
        print(f"{self.a=}")
        print(f"{self.b=}")
        print(f"{self.c=}")
        print(f"{self.d=}")
        print(f"{self.e=}")
        print(f"{self.f=}")
        print("--------")
    """

a, b, c, d, e, f = map(int, input().split())
dice = Dice(a, b, c, d, e, f)
li = list(input())
dice.move(li)
print(dice.a)

Submission status: Accepted

Solution code:
class Dice():
    def __init__(self, spots):
        self.spots = [spots[i] for i in range(6)]
    
    def roll(self, direction):
        if direction == 0:
            self.spots = [self.spots[i] for i in [1, 5, 2, 3, 0, 4]]
        elif direction == 1:
            self.spots = [self.spots[i] for i in [3, 1, 0, 5, 4, 2]]
        elif direction == 2:
            self.spots = [self.spots[i] for i in [4, 0, 2, 3, 5, 1]]
        elif direction == 3:
            self.spots = [self.spots[i] for i in [2, 1, 5, 0, 4, 3]]
            
    
spots = list(map(int, input().split()))
moves = input()
my_dice = Dice(spots=spots)
for move in moves:
    if move == 'N':
        my_dice.roll(0)
    elif move == 'E':
        my_dice.roll(1)
    elif move == 'S':
        my_dice.roll(2)
    elif move == 'W':
        my_dice.roll(3)
        
print(my_dice.spots[0])

Submission status: Accepted

Solution code:
class Dice:
    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 toN(self):
        tmp = self.top
        self.top = self.south
        self.south = self.bottom
        self.bottom = self.north
        self.north = tmp

    def toE(self):
        tmp = self.top
        self.top = self.west
        self.west = self.bottom
        self.bottom = self.east
        self.east = tmp

    def toS(self):
        tmp = self.top
        self.top = self.north
        self.north = self.bottom
        self.bottom = self.south
        self.south = tmp

    def toW(self):
        tmp = self.top
        self.top = self.east
        self.east = self.bottom
        self.bottom = self.west
        self.west = tmp

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


n = input().split()

dice = Dice(int(n[0]), int(n[1]), int(n[2]), int(n[3]), int(n[4]), int(n[5]))

order = input()
for o in order:
    if o == "N":
        dice.toN()
    elif o == "E":
        dice.toE()
    elif o == "S":
        dice.toS()
    elif o == "W":
        dice.toW()

dice.printTop()

Submission status: Accepted

Solution code:
class Dice:
    def __init__(self, ary): # [top, front, right, left, back, bottom]
        self.__top = ary[0]
        self.__fro = ary[1]
        self.__rit = ary[2]
        self.__lft = ary[3]
        self.__bak = ary[4]
        self.__btm = ary[5]

    def turn_e(self): # 右に転がる
        self.__top, self.__lft, self.__btm, self.__rit = \
        self.__lft, self.__btm, self.__rit, self.__top

    def turn_s(self): # 手前に転がる
        self.__top, self.__fro, self.__btm, self.__bak = \
        self.__bak, self.__top, self.__fro, self.__btm

    def turn_w(self): # 左に転がる
        self.__top, self.__lft, self.__btm, self.__rit = \
        self.__rit, self.__top, self.__lft, self.__btm

    def turn_n(self): # 奥に転がる
        self.__top, self.__fro, self.__btm, self.__bak = \
        self.__fro, self.__btm, self.__bak, self.__top

    def spin_r(self): # 右回転 
        self.__rit, self.__fro, self.__lft, self.__bak = \
        self.__bak, self.__rit, self.__fro, self.__lft

    def spin_l(self): # 左回転
        self.__rit, self.__fro, self.__lft, self.__bak = \
        self.__fro, self.__lft, self.__bak, self.__rit

    def is_same_setting(self, ary): # 同じように置いているか
        if self.__top == ary[0] and self.__fro == ary[1] and self.__rit == ary[2] and \
            self.__lft == ary[3] and self.__bak == ary[4] and self.__btm == ary[5]:
            return True

    def is_same_dice(self, ary): # 回転させて同じダイスになるか
        is_same = False
        for _ in range(2):
            for _ in range(3):
                for _ in range(4):
                    if self.is_same_setting(ary):
                        is_same = True
                    self.spin_r()
                self.turn_n()
            self.spin_r()
            self.turn_s()
        return is_same

    def show_top(self): # 上面の値を表示
        return self.__top

surfaces = list(map(int,input().split()))
instructions = list(input())

dice = Dice(surfaces)

for inst in instructions:
    if inst == "E":
        dice.turn_e()
    if inst == "N":
        dice.turn_n()
    if inst == "S":
        dice.turn_s()
    if inst == "W":
        dice.turn_w()

print(dice.show_top())

Submission status: Accepted

Solution code:
# import dice
class dice:
    def __init__(self):
        self.top = 1
        # self.srf = [[2,4,3,5],[6,4,3,1],[6,2,5,1],[6,5,2,1],[6,4,3,1],[5,4,3,2]]
        self.bottom = 2
        self.up = 5
        self.left = 4
        self.right = 3
        self.reverse = 6
    def move(self, dim):
        if dim == "N":
            temp = self.top
            self.top = self.bottom
            self.bottom = self.reverse
            self.reverse = self.up
            self.up = temp
        elif dim == "E":
            temp = self.top
            self.top = self.left
            self.left = self.reverse
            self.reverse = self.right
            self.right = temp
        elif dim == "W":
            temp = self.top
            self.top = self.right
            self.right = self.reverse
            self.reverse = self.left
            self.left = temp
        elif dim == "S":
            temp = self.top
            self.top = self.up
            self.up = self.reverse
            self.reverse = self.bottom
            self.bottom = temp

x = []
x = list(map(int, input().split()))
mv = []
mv = list(input())
dc = dice()

for i in range(len(mv)):
    dc.move(mv[i])
    
print(x[dc.top - 1])

Submission status: Accepted

Solution code:

import sys
input = sys.stdin.readline


class Dice:
    """
    0:top, 1:south, 2:east, 3:west, 4:north, 5:bottom
    """

    def __init__(self, surfaces):
        self.surface = surfaces

    def roll(self, direction: str):
        if direction == "E":
            self.surface = [self.surface[3], self.surface[1], self.surface[0],
                            self.surface[5], self.surface[4], self.surface[2]]

        elif direction == "N":
            self.surface = [self.surface[1], self.surface[5], self.surface[2],
                            self.surface[3], self.surface[0], self.surface[4]]

        elif direction == "S":
            self.surface = [self.surface[4], self.surface[0], self.surface[2],
                            self.surface[3], self.surface[5], self.surface[1]]

        elif direction == "W":
            self.surface = [self.surface[2], self.surface[1], self.surface[5],
                            self.surface[0], self.surface[4], self.surface[3]]

        return

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


def main():
    surface = [int(i) for i in input().strip().split()]
    spins = input().strip()
    dice = Dice(surface)
    for d in spins:
        dice.roll(d)
    print(dice.get_top())


if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:
class Dice(object):
    def __init__(self):
        self.number = [0 for _ in range(6)]
        self.before = [0 for _ in range(6)]

    def set_number(self, l):
        for i in range(6):
            self.number[i] = l[i]

    def roll(self, loc):
        d = {
            '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)
        }
        for i in range(6):
            self.before[i] = self.number[i]

        for i, j in enumerate(d[loc]):
            self.number[i] = self.before[j]

    def get_Top(self):
        return self.number[0]


if __name__ == '__main__':
    l = list(map(int, input().split()))
    dice = Dice()
    dice.set_number(l)
    s = input()
    for i in s:
        dice.roll(i)
    print(dice.get_Top())

Submission status: Accepted

Solution code:
class dice:
    def __init__(self,A):
        self.side = {
            "TOP":A[0],
            "S":A[1],
            "E":A[2],
            "W":A[3],
            "N":A[4],
            "BOT":A[5],
            }
        self.reverse = {
            "E":"W",
            "W":"E",
            "S":"N",
            "N":"S"}
        
    def main(self,A):
        for s in A:
            var = int(self.side[s])
            self.side[s] = self.side["TOP"]
            self.side["TOP"] = self.side[self.reverse[s]]
            self.side[self.reverse[s]] = self.side["BOT"]
            self.side["BOT"] = var
        print("{}".format(self.side["TOP"]))

var = dice(list(map(int,input().split())))
var.main(input())

Submission status: Accepted

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

Submission status: Accepted

Solution code:
class dice():
    def __init__(self, num_list):
        self.dice_index = 0
        i = self.dice_index
        self.NS = [num_list[i], num_list[i+1], num_list[i+5], num_list[i+4]]
        self.WE = [num_list[i], num_list[i+2], num_list[i+5], num_list[i+3]]

    def set_dict(self, direction):
        i = self.dice_index
        if direction == 'N' or direction == 'W':
            m = 1
        elif direction == 'S' or direction == 'E':
            m = -1
        if direction == 'N' or direction == 'S':
            self.dice_index = self.NS[m]
            self.NS = self.NS[m:]+self.NS[:m]
            self.WE[0] = self.NS[0]
            self.WE[2] = self.NS[2]
        elif direction == 'W' or direction == 'E':
            self.dice_index = self.WE[m]
            self.WE = self.WE[m:]+self.WE[:m]
            self.NS[0] = self.WE[0]
            self.NS[2] = self.WE[2]


if __name__ == '__main__':
    dice_number = input()
    dice_direction = input()
    dice_number = dice_number.split()
    Dice = dice(dice_number)
    for i in range(len(dice_direction)):
        Dice.set_dict(dice_direction[i])
    else:
        print(Dice.dice_index)

Submission status: Accepted

Solution code:
dice = list(input().split(' '))
a = list(input())
for i in a:
    if i == 'W':
        dice = [dice[2],dice[1],dice[5],dice[0],dice[4],dice[3]]
    elif i == 'S':
        dice = [dice[4],dice[0],dice[2],dice[3],dice[5],dice[1]]
    elif i == 'N':
        dice = [dice[1],dice[5],dice[2],dice[3],dice[0],dice[4]]
    elif i == 'E':
        dice = [dice[3],dice[1],dice[0],dice[5],dice[4],dice[2]]
print(dice[0])

Submission status: Accepted

Solution code:
class Dice:
    top = 0
    def __init__(self,one,two,three,four,five,six):
        self.one = one
        self.two = two
        self.three = three
        self.four = four
        self.five = five
        self.six = six

    def role(self,direction):
        global top
        if(direction == 'S'):
                t1 = self.one
                self.one = self.five
                t2 = self.two
                self.two = t1
                t3 = self.six
                self.six = t2
                t4 = self.five
                self.five = t3
                top = self.one
       
        if(direction == 'E'):
            t1 = self.one
            self.one = self.four
            t2 = self.three
            self.three = t1
            t3 = self.six
            self.six = t2
            self.four = t3
            top = self.one
        if(direction == 'N'):
            t1 = self.one
            t2 = self.two
            t5 = self.five
            t6 = self.six
            self.one = t2
            self.two = t6
            self.six = t5
            self.five = t1
            top = self.one
        if(direction == 'W'):
            t1 = self.one
            t3 = self.three
            t4 = self.four
            t6 = self.six
            self.one = t3
            self.four = t1
            self.six = t4
            self.three = t6
            top = self.one
            
        return(top)
arr = [int(i) for i in input().split()]
op = str(input())
final = 0
a = Dice(arr[0],arr[1],arr[2],arr[3],arr[4],arr[5])
for i in range(len(op)):
     final = a.role(op[i])
print(final)

Submission status: Accepted

Solution code:
class Dice():
    def __init__(self):
        self.num = [0 for _ in range(6)]
    
    def set_num(self, n0, n1, n2, n3, n4, n5):
        self.num[0] = n0
        self.num[1] = n1
        self.num[2] = n2
        self.num[3] = n3
        self.num[4] = n4
        self.num[5] = n5
    
    def roll(self, order):
        tmp = self.num.copy()
        
        if order == "N":
            self.set_num(tmp[1], tmp[5], tmp[2], tmp[3], tmp[0], tmp[4])
        elif order == "S":
            self.set_num(tmp[4], tmp[0], tmp[2], tmp[3], tmp[5], tmp[1])
        elif order == "E":
            self.set_num(tmp[3], tmp[1], tmp[0], tmp[5], tmp[4], tmp[2])
        elif order == "W":
            self.set_num(tmp[2], tmp[1], tmp[5], tmp[0], tmp[4], tmp[3])
        else:
            print("Error: 不正な入力です")

    def get_top_num(self):
        return self.num[0]
        
    
# Input
init_num = [int(_) for _ in input().split()]
order_string = str(input())

# Main 
dice = Dice()
dice.set_num(init_num[0], init_num[1], init_num[2], init_num[3], init_num[4], init_num[5])

for i, order in enumerate(order_string):
    dice.roll(order)

print(dice.get_top_num())

Submission status: Accepted

Solution code:
from operator import itemgetter
faces = list(map(int, input().split()))
commands = input()

for command in commands:
    if command == 'N':
        faces = itemgetter(1,5,2,3,0,4)(faces)
    elif command == 'E':
        faces = itemgetter(3,1,0,5,4,2)(faces)
    elif command == 'S':
        faces = itemgetter(4,0,2,3,5,1)(faces)
    elif command == 'W':
        faces = itemgetter(2,1,5,0,4,3)(faces)
print(faces[0])

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)