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:
f1, f2, f3, f4, f5, f6 = map(int, input().split())

dice = {'f_top':f1, 'f_front':f2,'f_back':f5,'f_left':f4,'f_right':f3,'f_bottom':f6}

def roll(command, d):
    if command=='E':
        tmp = d['f_right']
        d['f_right'] = d['f_top']
        d['f_top'] = d['f_left']
        d['f_left'] = d['f_bottom']
        d['f_bottom'] = tmp
    elif command=='W':
        tmp = d['f_left']
        d['f_left'] = d['f_top']
        d['f_top'] = d['f_right']
        d['f_right'] = d['f_bottom']
        d['f_bottom'] = tmp
    elif command=='N':
        tmp = d['f_back']
        d['f_back'] = d['f_top']
        d['f_top'] = d['f_front']
        d['f_front'] = d['f_bottom']
        d['f_bottom'] = tmp
    elif command=='S':
        tmp = d['f_front']
        d['f_front'] = d['f_top']
        d['f_top'] = d['f_back']
        d['f_back'] = d['f_bottom']
        d['f_bottom'] = tmp
    return d
    
commands = input()
for s in commands:
    dice = roll(s, dice)

print(dice['f_top'])

Submission status: Accepted

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

  def vertical(self, direction):
    s = self.state
    state = [s[1], s[5], s[0], s[4]]
    if direction < 0:
      s[0], s[1], s[4], s[5] = state
    elif 0 < direction:
      s[0], s[1], s[4], s[5] = reversed(state)
    return self
  
  def lateral(self, direction):
    s = self.state
    state = [s[2], s[5], s[0], s[3]]
    if direction < 0:
      s[0], s[2], s[3], s[5] = state
    elif 0 < direction:
      s[0], s[2], s[3], s[5] = reversed(state)
    return self

  def north(self):
    self.vertical(-1)
    return self

  def south(self):
    self.vertical(1)
    return self
  
  def east(self):
    self.lateral(1)
    return self

  def west(self):
    self.lateral(-1)
    return self

dice = Dice(input().split())

for direction in list(input()):
  if direction == 'N':
    dice.north()
  elif direction == 'S':
    dice.south()
  elif direction == 'W':
    dice.west()
  elif direction == 'E':
    dice.east()

print(dice.state[0])

Submission status: Accepted

Solution code:
class Dise():
    def __init__(self, aLabelList):
        self.LabelList = aLabelList
        self.NEWS = {"N": [0,4,5,1], 
                     "E": [0,2,5,3], 
                     "W": [0,3,5,2], 
                     "S": [0,1,5,4]} 
        
    def move(self,aNEWS):
        idx = self.NEWS[aNEWS]
        
        tmp = self.LabelList[idx[0]]
        self.LabelList[idx[0]] = self.LabelList[idx[3]]
        self.LabelList[idx[3]] = self.LabelList[idx[2]]
        self.LabelList[idx[2]] = self.LabelList[idx[1]]
        self.LabelList[idx[1]] = tmp

    def DisePrint(self):
        print(self.LabelList[0])

myInstance = Dise(input().split())
 
x = input()
for i in range(len(x)):
    myInstance.move(x[i:i+1])

myInstance.DisePrint()

Submission status: Accepted

Solution code:
class dice:
    def __init__(s, i):
        s.d1,s.d2,s.d3,s.d4,s.d5,s.d6 = map(int, i)
    
    def W(s):
        tmp = s.d1
        s.d1 = s.d3
        s.d3 = s.d6
        s.d6 = s.d4
        s.d4 = tmp
        
    def E(s):
        tmp = s.d1
        s.d1 = s.d4
        s.d4 = s.d6
        s.d6 = s.d3
        s.d3 = tmp
        
    def N(s):
        tmp = s.d1
        s.d1 = s.d2
        s.d2 = s.d6
        s.d6 = s.d5
        s.d5 = tmp
        
    def S(s):
        tmp = s.d1
        s.d1 = s.d5
        s.d5 = s.d6
        s.d6 = s.d2
        s.d2 = tmp
        
dice1 = dice(input().split())
lst = list(input())
for s in lst:
    eval("dice1." + s)()
print(dice1.d1)

Submission status: Accepted

Solution code:
class  Dise:
    def __init__(self,top,flont,right,left,back,bottom):
        self.top,self.flont,self.right,self.left,self.back,self.bottom=top,flont,right,left,back,bottom
        
    def rot(self,d):
        if d=='N':
            self.top,self.flont,self.bottom,self.back=self.flont,self.bottom,self.back,self.top
        elif d=='E':
            self.top,self.right,self.bottom,self.left=self.left,self.top,self.right,self.bottom
        elif d=='S':
                self.top,self.flont,self.bottom,self.back=self.back,self.top,self.flont,self.bottom
        elif d=='W':
            self.top,self.right,self.bottom,self.left=self.right,self.bottom,self.left,self.top
    
    def gettop(self):
        return self.top

n=list(map(int,input().split()))
dise=Dise(n[0],n[1],n[2],n[3],n[4],n[5])
str=input()
for s in str:
    dise.rot(s)
print(dise.gettop())

Submission status: Accepted

Solution code:
#East[north][top] -> E
class Dice():
 East = [ [0,3,5,2,4,0]
		 ,[4,0,1,6,0,3]
		 ,[2,6,0,0,1,5]
		 ,[5,1,0,0,6,2]
		 ,[3,0,6,1,0,4]
		 ,[0,4,2,5,3,0]
		 ]
 def __init__(self,N):
  self.label = N
  self.top = 1
  self.north = 5
 def move(self,ori):
  if ori=='S':
   t = self.top
   self.top = self.north
   self.north = 7-t
  elif ori=='N':
   t = self.top
   self.top = 7-self.north
   self.north = t
  elif ori=='E':
   east = self.East[self.north-1][self.top-1]
   self.top = 7-east
  elif ori=='W':
   east = self.East[self.north-1][self.top-1]
   self.top = east
 def gettop(self):
  return( self.label[self.top-1] )

label = list(map(int, input().split() ))
D = Dice(label)
command = input()
for ci in range(len(command)):
 D.move(command[ci])
 #print(D.top,D.north)
print(D.gettop())

Submission status: Accepted

Solution code:
#アルゴリズム関数
def dice_rotation(list, direction):
    if direction == "S":
        list[0],list[1],list[4],list[5] = list[4],list[0],list[5],list[1]
    elif direction == "E":
        list[0],list[2],list[3],list[5] = list[3],list[0],list[5],list[2]
    elif direction == "N":
        list[0],list[1],list[4],list[5] = list[1],list[5],list[0],list[4]
    elif direction == "W":
        list[0],list[2],list[3],list[5] = list[2],list[5],list[0],list[3]
    return list

#インプットdataの格納
input_number = list(map(int, input().split()))
input_order = input()

#処理の実行
for order in input_order:
    input_number = dice_rotation(input_number, order)

#結果表示
print(input_number[0])

Submission status: Accepted

Solution code:
class Dice:
    def __init__(self, x):
        self.top = x[0]
        self.front = x[1]
        self.right = x[2]
        self.left = x[3]
        self.back = x[4]
        self.bottom = x[5]

    def N(self):
        self.top, self.front, self.bottom, self.back = self.front, self.bottom, self.back, self.top

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

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

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

*x,=map(int,input().split())
dice=Dice(x)
A=input()
for a in A:
    if a=='N':
        dice.N()
    if a=='E':
        dice.E()
    if a=='S':
        dice.S()
    if a=='W':
        dice.W()
print(dice.top)

Submission status: Accepted

Solution code:
import math

class Dice():
    top   = 0 #上
    left  = 0 #左
    right = 0 #右
    front = 0 #前面
    back  = 0 #後面
    below = 0 #真下

    DEBUG_MODE = False
    def __init__(self,lst,dbg = False):
        if len(lst) == 6:
            self.top   = lst[0]
            self.front = lst[1]
            self.right = lst[2]
            self.left  = lst[3]
            self.back  = lst[4]
            self.below = lst[5]

        if dbg == True:
            self.DEBUG_MODE = True
        else:
            self.DEBUG_MODE = False
    
    def rotate(self,string):
        
        for ch in string:
            if   ch == 'W':
                self.left,self.top,self.right,self.below = self.top,self.right,self.below,self.left

            elif ch == 'E':
                self.left,self.top,self.right,self.below = self.below,self.left,self.top,self.right

            elif ch == 'S':
                self.top,self.back,self.below,self.front = self.back,self.below,self.front,self.top

            elif ch == 'N':
                self.top,self.back,self.below,self.front = self.front,self.top,self.back,self.below
            
            # デバッグモードなら全部の値をモニタする
            if self.DEBUG_MODE:
                self.dbg_PRINT_ALL_VALUE()

        
    def get_topvalue(self):
        return self.top
    
    def dbg_PRINT_ALL_VALUE(self):
        print(f"        bk:{self.back:04} ")
        print(f"le:{self.left:04} tp:{self.top:04} ri:{self.right:04} be:{self.below:04}")
        print(f"        fr:{self.front:04} ")

lst = list(map(int,input().split()))
#lst = [1,2,3,4,5,6]
dice = Dice(lst)
dice.rotate(input())
print(dice.get_topvalue())

Submission status: Accepted

Solution code:
label = list(map(int,input().split()))
direction = list(str(input()))
D=list(range(6))
Dtemp=[0,0,0,0,0,0]
for i in range(len(direction)):
    if direction[i] == 'N':
        Dtemp[0] = D[1]
        Dtemp[1] = D[5]
        Dtemp[2] = D[2]
        Dtemp[3] = D[3]
        Dtemp[4] = D[0]
        Dtemp[5] = D[4]
    elif direction[i] == 'E':
        Dtemp[0] = D[3]
        Dtemp[1] = D[1]
        Dtemp[2] = D[0]
        Dtemp[3] = D[5]
        Dtemp[4] = D[4]
        Dtemp[5] = D[2]
    elif direction[i] =='S':
        Dtemp[0] = D[4]
        Dtemp[1] = D[0]
        Dtemp[2] = D[2]
        Dtemp[3] = D[3]
        Dtemp[4] = D[5]
        Dtemp[5] = D[1]
    elif direction[i] =='W':
        Dtemp[0] = D[2]
        Dtemp[1] = D[1]
        Dtemp[2] = D[5]
        Dtemp[3] = D[0]
        Dtemp[4] = D[4]
        Dtemp[5] = D[3]
    D=Dtemp
    Dtemp=[0,0,0,0,0,0]
print(label[D[0]])

Submission status: Accepted

Solution code:
class Dice_roll:
    face_num = []
    def move(self,way):
        if way == "N":
            self.face_num = [self.face_num[1],self.face_num[5],self.face_num[2],self.face_num[3],self.face_num[0],self.face_num[4]]
            
        elif way == "S":
            self.face_num = [self.face_num[4],self.face_num[0],self.face_num[2],self.face_num[3],self.face_num[5],self.face_num[1]]
            
        elif way == "W":
            self.face_num = [self.face_num[2],self.face_num[1],self.face_num[5],self.face_num[0],self.face_num[4],self.face_num[3]]
            
        elif way == "E":
            self.face_num = [self.face_num[3],self.face_num[1],self.face_num[0],self.face_num[5],self.face_num[4],self.face_num[2]]        

dice = Dice_roll()
               
dice.face_num = list(map(int,input().split()))

direction = str(input())
  
for i in direction:
    dice.move(i)

print(dice.face_num[0])

Submission status: Accepted

Solution code:
class Dice:
    def __init__(self, dice):
        self.dice = dice
        self.rule={'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)}
    def output(self):
        return self.dice
    def move(self, direction):
        self.dice = [self.dice[y] for y in self.rule[_]]
        return self.dice

dice = Dice([int(x) for x in input().split()])
for _ in input(): dice.move(_)
print(dice.output()[0])

Submission status: Accepted

Solution code:
nums = list(map(int, input().split()))
s = input()

l1 = [1, 4, 6, 3]
l2 = [l1[0], 2, l1[2], 5]

for char in s:
    if char == "W":
        l1 = [l1[3], l1[0], l1[1], l1[2]]
        l2[0] = l1[0]
        l2[2] = l1[2]
    elif char == "E":
        l1 = [l1[1], l1[2], l1[3], l1[0]]
        l2[0] = l1[0]
        l2[2] = l1[2]
    elif char == "N":
        l2 = [l2[1], l2[2], l2[3], l2[0]]
        l1[0] = l2[0]
        l1[2] = l2[2]
    elif char == "S":
        l2 = [l2[3], l2[0], l2[1], l2[2]]
        l1[0] = l2[0]
        l1[2] = l2[2]

print(nums[l1[0] - 1])

Submission status: Accepted

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

lis = [1,2,3,4,5,6]

def dicing(lis, inst):
    if inst == 'N':
        ans_lis = [lis[1],lis[5],lis[2],lis[3],lis[0],lis[4]]
    if inst == 'W':
        ans_lis = [lis[2],lis[1],lis[5],lis[0],lis[4],lis[3]]
    if inst == 'S':
        ans_lis = [lis[4],lis[0],lis[2],lis[3],lis[5],lis[1]]
    if inst == 'E':
        ans_lis = [lis[3],lis[1],lis[0],lis[5],lis[4],lis[2]]
    
    return(ans_lis)

inst = list(input())
N = len(inst)

for i in range(N):
    lis = dicing(lis, inst[i])

print(dice[(lis[0]-1)])

Submission status: Accepted

Solution code:
# Dice I
class Dice:
    def __init__(self, default_surface):
        self.dice = default_surface  # [T, B, U, D, L, R]
        self.rotation_count = 0

    def move(self, new_face: int) -> None:
        for i, face in enumerate(self.dice):  # move new_face to dice[0]
            if face != new_face:
                continue
            elif i == 1:
                self.roll_up(), self.roll_up()
            elif i == 2:
                self.roll_left()
            elif i == 3:
                self.roll_right()
            elif i == 4:
                self.roll_up()
            elif i == 5:
                self.roll_down()

    def roll_left(self) -> None:
        self.dice[0], self.dice[3], self.dice[1], self.dice[2] = self.dice[2], self.dice[0], self.dice[3], self.dice[1]
        self.rotation_count += 1

    def roll_right(self) -> None:
        self.dice[0], self.dice[2], self.dice[1], self.dice[3] = self.dice[3], self.dice[0], self.dice[2], self.dice[1]
        self.rotation_count += 1

    def roll_up(self) -> None:
        self.dice[0], self.dice[5], self.dice[1], self.dice[4] = self.dice[4], self.dice[0], self.dice[5], self.dice[1]
        self.rotation_count += 1

    def roll_down(self) -> None:
        self.dice[0], self.dice[4], self.dice[1], self.dice[5] = self.dice[5], self.dice[0], self.dice[4], self.dice[1]
        self.rotation_count += 1

    def roll_clockwise(self) -> None:
        self.dice[2], self.dice[4], self.dice[3], self.dice[5] = self.dice[5], self.dice[2], self.dice[4], self.dice[3]
        self.rotation_count += 1

    def roll_counterclockwise(self) -> None:
        self.dice[2], self.dice[5], self.dice[3], self.dice[4] = self.dice[4], self.dice[2], self.dice[5], self.dice[3]
        self.rotation_count += 1


def main():
    T, L, U, D, R, B = map(int, input().split())
    order = input().rstrip()
    dice = Dice([T, B, U, D, L, R])
    for c in order:
        if c == "E":
            dice.roll_right()
        if c == "W":
            dice.roll_left()
        if c == "N":
            dice.roll_up()
        if c == "S":
            dice.roll_down()
    print(dice.dice[0])


if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:
# サイコロクラス
class Dice:
    # 初期化(サイコロの面データを設定)
    def __init__(self, dice_surface_str):
        dice_surface_list = [int(i) for i in dice_surface_str.split()]
        self.dice_surface = dice_surface_list

    # インデックスを指定したサイコロの面を返す(デフォルトは全面)
    def return_surface(self, return_surface_index=""):
        if return_surface_index == "":
            return self.dice_surface
        else:
            return self.dice_surface[return_surface_index]

    # インデックスを指定したサイコロの面を出力(デフォルトは全面)
    def print_surface(self, print_surface_index=""):
        print(self.return_surface(print_surface_index))

    # サイコロを転がした時の面の遷移を返す
    def dice_roll_transition(self, direction):
        roll_dict = {"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]}
        if direction == "N" or direction == "E" or direction == "W" or direction == "S":
            roll_list = roll_dict[direction]
        #if direction == "N":
        #    roll_list = [1, 5, 2, 3, 0, 4]
        #elif direction == "E":
        #    roll_list = [3, 1, 0, 5, 4, 2]
        #elif direction == "W":
        #    roll_list = [2, 1, 5, 0, 4, 3]
        #elif direction == "S":
        #    roll_list = [4, 0, 2, 3, 5, 1]
        else:
            print("命令が不正です")
            print(f"不正な入力データ : {direction}")
        return roll_list

    # サイコロを転がす
    def dice_roll(self, order):
        for o in order:
            surface_tmp = self.return_surface()
            surface_after_roll = []
            surface_after_roll = [surface_tmp[d] for d in self.dice_roll_transition(o)]
            self.dice_surface = surface_after_roll

# 処理実行
## サイコロの面データを受け取る
dc = input()
## インスタンス化
hoge = Dice(dc)
## 命令を受け取る
inp_order = input()
## 命令を実行
hoge.dice_roll(inp_order)
## 上面を出力
hoge.print_surface(0)

Submission status: Accepted

Solution code:
pattern = {'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_num = input().split()
for x in input():
    dice_num = [dice_num[i] for i in pattern[x]]
print(dice_num[0])

Submission status: Accepted

Solution code:
class Dice:
    def __init__(self, e1, e2, e3, e4, e5, e6):
        self.eye1 = e1
        self.eye2 = e2
        self.eye3 = e3
        self.eye4 = e4
        self.eye5 = e5
        self.eye6 = e6
    
    def roll_e(self):
        tmp_eye   = self.eye3
        self.eye3 = self.eye1
        self.eye1 = self.eye4
        self.eye4 = self.eye6
        self.eye6 = tmp_eye
    
    def roll_n(self):
        tmp_eye   = self.eye5
        self.eye5 = self.eye1
        self.eye1 = self.eye2
        self.eye2 = self.eye6
        self.eye6 = tmp_eye
    
    def roll_s(self):
        tmp_eye   = self.eye2
        self.eye2 = self.eye1
        self.eye1 = self.eye5
        self.eye5 = self.eye6
        self.eye6 = tmp_eye
    
    def roll_w(self):
        tmp_eye   = self.eye4
        self.eye4 = self.eye1
        self.eye1 = self.eye3
        self.eye3 = self.eye6
        self.eye6 = tmp_eye
    
    def get_eye1(self):
        return self.eye1

e1, e2, e3, e4 ,e5, e6 = map(int,input().split())
dice1 = Dice(e1, e2, e3, e4 ,e5, e6)
roll = input()
for i in range(len(roll)):
    if roll[i] == 'E':
        dice1.roll_e()
    if roll[i] == 'N':
        dice1.roll_n()
    if roll[i] == 'S':
        dice1.roll_s()
    if roll[i] == 'W':
        dice1.roll_w()
print(dice1.get_eye1())

Submission status: Accepted

Solution code:
from collections import deque

class Dice():
    def __init__(self, sequence):
        self.v = deque([seq[5], seq[4], seq[0], seq[1]])
        self.h = deque([seq[3], seq[0], seq[2], seq[5]])

    def lotate(self, direction):

        if   direction == "E":
            self.h.rotate()
            self.v[2] = self.h[1]
            self.v[0] = self.h[3]

        elif direction == "W":
            self.h.rotate(-1)
            self.v[2] = self.h[1]
            self.v[0] = self.h[3]

        elif direction == "N":
            self.v.rotate(-1)
            self.h[1] = self.v[2]
            self.h[3] = self.v[0]

        elif direction == "S":
            self.v.rotate()
            self.h[1] = self.v[2]
            self.h[3] = self.v[0]

        else:
            pass

    def disp_top_face(self):
        return self.v[2]

    def disp_front_face(self):
        return self.v[3]

    def disp_back_face(self):
        return self.v[1]

    def disp_right_face(self):
        return self.h[2]

    def disp_left_face(self):
        return self.h[0]

    def disp_bottom_face(self):
        return self.h[3]

if __name__ == "__main__":

    param = input().split(" ")
    seq = [int(a) for a in param]

    com = input()

    d = Dice(seq)
    for dir in com:
        d.lotate(dir)

    print(d.disp_top_face())

Submission status: Accepted

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

    def roll(self, str_direction):
        if str_direction == 'E':
            self.__rot_to_east()
        elif str_direction == 'W':
            self.__rot_to_west()
        elif str_direction == 'S':
            self.__rot_to_south()
        elif str_direction == 'N':
            self.__rot_to_north()

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

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

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

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

dice_labels = input().split(' ')
rot_operations = list(input())
dice = Dice(dice_labels)

for roll_direction in rot_operations:
    dice.roll(roll_direction)

print(dice.top)

Submission status: Accepted

Solution code:
D = [
    (1, 5, 2, 3, 0, 4), # 'U'
    (3, 1, 0, 5, 4, 2), # 'R'
    (4, 0, 2, 3, 5, 1), # 'D'
    (2, 1, 5, 0, 4, 3), # 'L'
]
C = 'NESW'

*L, = map(int, input().split())
for c in input():
    L[:] = (L[e] for e in D[C.index(c)])
print(L[0])

Submission status: Accepted

Solution code:
def lotate(dic, dire):
    if dire == 'N':
        x,y,z,w = dic['up'], dic['back'], dic['bottom'], dic['front']
        dic['back'], dic['bottom'], dic['front'], dic['up'] = x,y,z,w
    elif dire == 'S':
        x, y, z, w = dic['up'], dic['back'], dic['bottom'], dic['front']
        dic['front'], dic['up'], dic['back'], dic['bottom'] = x, y, z, w
    elif dire == 'W':
        x, y, z, w = dic['up'], dic['left'], dic['bottom'], dic['right']
        dic['left'], dic['bottom'], dic['right'], dic['up'] = x, y, z, w
    elif dire == 'E':
        x, y, z, w = dic['up'], dic['left'], dic['bottom'], dic['right']
        dic['right'], dic['up'], dic['left'], dic['bottom'] = x, y, z, w
    return dic


a,b,c,d,e,f = map(int, input().split())
d = {'up':a, 'front':b, 'right':c, 'left':d, 'back':e, 'bottom':f}
s = input()
for i in s:
    d = lotate(d, i)
print(d['up'])

Submission status: Accepted

Solution code:
class Dice(object):

    def __init__(self, *args):
        self.faces = [None]
        self.faces.extend(args)
        self.top = self.faces[1]
        self.up = self.faces[5]
        self.down = self.faces[2]
        self.left = self.faces[4]
        self.right = self.faces[3]

    def roll(self, direction):
        if direction == "N":
            self.top, self.up, self.down = self.down, self.top, self.faces[7 - self.faces.index(self.top)]
        elif direction == "S":
            self.top, self.up, self.down = self.up, self.faces[7 - self.faces.index(self.top)], self.top
        elif direction == "W":
            self.top, self.left, self.right = self.right, self.top, self.faces[7 - self.faces.index(self.top)]
        elif direction == "E":
            self.top, self.left, self.right = self.left, self.faces[7 - self.faces.index(self.top)], self.top
        else:
            raise ValueError("{} is not valid direction.".format(direction))

    def get_top(self):
        return self.top


f = [int(i) for i in input().split()]
dice = Dice(*f)
for d in input():
    dice.roll(d)

print(dice.get_top())

Submission status: Accepted

Solution code:
class Dice():
    def __init__(self, up, back, right, left, front, down):
        self.up = up
        self.down = down
        self.right = right
        self.left = left
        self.front = front
        self.back = back
    
    def north(self):
        temp = self.up
        self.up = self.back
        self.back = self.down
        self.down = self.front
        self.front = temp
    
    def south(self):
        temp = self.up
        self.up = self.front
        self.front = self.down
        self.down = self.back
        self.back = temp
        
    def east(self):
        temp = self.up
        self.up = self.left
        self.left = self.down
        self.down = self.right
        self.right = temp
    
    def west(self):
        temp = self.up
        self.up = self.right
        self.right = self.down
        self.down = self.left
        self.left = temp
        
    def operate(self, op):
        if op == "N":
            self.north()
        elif op == "S":
            self.south()
        elif op == "E":
            self.east()
        elif op == "W":
            self.west()
        
        
up, back, right, left, front, down = map(int, input().split())
dice = Dice(up, back, right, left, front, down)

op_str = input()

for op in op_str:
    dice.operate(op)

print(dice.up)

Submission status: Accepted

Solution code:
from collections import deque


class Dice:
    def __init__(self, *surface):
        self._surface = surface

        self._mapping_sn = deque([0, 1, 5, 4], maxlen=4)
        self._mapping_we = deque([0, 3, 5, 2], maxlen=4)

    @property
    def top(self):
        return self._surface[self._mapping_sn[0]]

    def roll_s(self):
        self._mapping_sn.rotate(1)
        self._mapping_we[0] = self._mapping_sn[0]
        self._mapping_we[2] = self._mapping_sn[2]

    def roll_n(self):
        self._mapping_sn.rotate(-1)
        self._mapping_we[0] = self._mapping_sn[0]
        self._mapping_we[2] = self._mapping_sn[2]

    def roll_w(self):
        self._mapping_we.rotate(1)
        self._mapping_sn[0] = self._mapping_we[0]
        self._mapping_sn[2] = self._mapping_we[2]

    def roll_e(self):
        self._mapping_we.rotate(-1)
        self._mapping_sn[0] = self._mapping_we[0]
        self._mapping_sn[2] = self._mapping_we[2]


if __name__ == '__main__':
    surface = map(int, input().split())
    d = Dice(*surface)
    commands = list(input().lower())
    for c in commands:
        getattr(d, 'roll_' + c)()
    print(d.top)

Submission status: Accepted

Solution code:
initial=list( map(int,input().split()))
change=initial

def East(a,b,c,d,e,f):
    return [d, b, a, f, e, c]

def West(a,b,c,d,e,f):
    return [c, b, f, a, e, d]

def South(a,b,c,d,e,f):
    return [e, a, c, d, f, b]

def North(a,b,c,d,e,f):
    return [b, f, c, d, a, e]



a=input()

for idx in range(0, len(a)):
    if a[idx]=="E":
        change=East(*change)
    elif a[idx]=="W":
        change=West(*change)
    elif a[idx]=="S":
        change=South(*change)
    elif a[idx]=="N":
        change=North(*change)
print(change[0])

Submission status: Accepted

Solution code:
class Dice():
    top=1
    n=2
    e=4
    w=3
    s=5
    dice=[1,2,3,4,5,6]
    def __init__(self,num):
        self.dice=num

    def roll(self,direction):
        if(direction=="N"):
            self.top,self.n,self.s = self.n,7-self.top,self.top
        elif(direction=="E"):
            self.top,self.e,self.w = self.e,7-self.top,self.top
        elif(direction=="W"):
            self.top,self.e,self.w = self.w,self.top,7-self.top
        elif(direction=="S"):
            self.top,self.n,self.s = self.s,self.top,7-self.top


d=list(map(int,input().split()))
dice=Dice(d)
direct=list(input())
for i in range(len(direct)):
    dice.roll(direct[i])

print(dice.dice[dice.top-1])

Submission status: Accepted

Solution code:
a=[]
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]


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



n = input()
b=[0]*6
for i in range(len(n)):
    for j in range(6):b[j] = a[j]
    
    if n[i] == "N":
        for j in range(6):
            a[j] = b[N[j]]    
        
    elif n[i] == "S":
        for j in range(6):
            a[j] = b[S[j]]
        
    elif n[i] == "W":
        for j in range(6):
            a[j] = b[W[j]]
        
    elif n[i] == "E":
        for j in range(6):
            a[j] = b[E[j]]

print(a[0])

Submission status: Accepted

Solution code:
class Dice:
    def __init__(self,u,s,e,w,n,d):
        self.u = u
        self.s = s
        self.e = e
        self.w = w
        self.n = n
        self.d = d
        self.dir = {'W':0,'S':1,'E':2,'N':3}
    
    def rot(self,way):
        if isinstance(way,str):
            way = self.dir[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,s,e,w,n,d)
direct = input()

for d in direct:
    dice.rot(d)

print(dice.u)

Submission status: Accepted

Solution code:
s = list(map(int, input().split()))
dl = input()
stmp = [0] * 6

dr = {"N": [1, 5, 2, 3, 0, 4],
      "W": [2, 1, 5, 0, 4, 3],
      "S": [4, 0, 2, 3, 5, 1],
      "E": [3, 1, 0, 5, 4, 2]}
for d in dl:
    drs = dr[d]
    for i in range(6):
        stmp[i] = s[drs[i]]
    s = list(stmp)
    #print(s)
print(s[0])

Submission status: Accepted

Solution code:
face = [0]*6
class Dice():

    def __init__(self):
        self.one = inp[0]
        self.two = inp[1]
        self.three = inp[2]
        self.four = inp[3]
        self.five = inp[4]
        self.six = inp[5]

    def setnumbers(self, n0, n1, n2, n3, n4, n5):
        self.one = n0
        self.two = n1
        self.three = n2
        self.four = n3
        self.five = n4
        self.six = n5


    def spin(self, command):
        face[0] = self.one
        face[1] = self.two
        face[2] = self.three
        face[3] = self.four
        face[4] = self.five
        face[5] = self.six
        if command == 'S':
            self.setnumbers(face[4], face[0], face[2], face[3], face[5], face[1])
            # print('command is S')
        elif command == 'N':
            self.setnumbers(face[1], face[5], face[2], face[3], face[0], face[4])
            # print('command is N')
        elif command == 'E':
            self.setnumbers(face[3], face[1], face[0], face[5], face[4], face[2])
            # print('command is E')
        elif command == 'W':
            self.setnumbers(face[2], face[1], face[5], face[0], face[4], face[3])
            # print('command is W')

inp = list(map(int, input().split()))
command = list(input())

dice = Dice()

dice.setnumbers(inp[0], inp[1], inp[2], inp[3], inp[4], inp[5])
face = inp
for i in range(len(command)):
    dice.spin(command[i])
print(dice.one)

Submission status: Accepted

Solution code:
f6=list(map(int,input().split()))
t=[0]*6
cmd=input()
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)}
for c in cmd:
    for i in range(6):
        t[i]=f6[r[c][i]]
    f6,t=t,f6
print(f6[0])