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:
# -*- coding: utf-8 -*-
# ITP1_11_A

class Dice:
    def __init__(self, num):
        self.num = num
        
    def show(self):
        """ 出目を表示する """
        print(self.num[0])
        
    def roll(self, direction):
        """ NSEWへ転がしたときの処理 """
        new_num = []
        if direction == "N":
            data = [1, 5, 2, 3, 0, 4]
        elif direction == "S":
            data = [4, 0, 2, 3, 5, 1]
        elif direction == "E":
            data = [3, 1, 0, 5, 4, 2]
        elif direction == "W":
            data = [2, 1, 5, 0, 4, 3]
        for i in data:
            new_num.append(self.num[i])
        self.num = new_num
        
dice_num = list(map(int, input().split()))
dice_roll = input()

dice1 = Dice(dice_num)

for direction in dice_roll:
    dice1.roll(direction)
dice1.show()

Submission status: Accepted

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

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:
class Dice():
    def __init__(self,rot,Face):
        self.rot= rot
        self.Face = Face
    def Rotate(rot,Face):
        r=len(rot)
        intFace=[int(Face[i]) for i in range(6)]

        for i in range(r):
            Temp=[intFace[i] for i in range(6)]

            if rot[i]== "E":
                intFace[0]=Temp[3]
                intFace[1]=Temp[1]
                intFace[2]=Temp[0]
                intFace[3]=Temp[5]
                intFace[4]=Temp[4]
                intFace[5]=Temp[2]

            elif rot[i]== "W":
                intFace[0]=Temp[2]
                intFace[1]=Temp[1]
                intFace[2]=Temp[5]
                intFace[3]=Temp[0]
                intFace[4]=Temp[4]
                intFace[5]=Temp[3]

            elif rot[i]== "N":
                intFace[0]=Temp[1]
                intFace[1]=Temp[5]
                intFace[2]=Temp[2]
                intFace[3]=Temp[3]
                intFace[4]=Temp[0]
                intFace[5]=Temp[4]


            elif rot[i]== "S":
                intFace[0]=Temp[4]
                intFace[1]=Temp[0]
                intFace[2]=Temp[2]
                intFace[3]=Temp[3]
                intFace[4]=Temp[5]
                intFace[5]=Temp[1]


        return intFace
#returnしてなかったわ インデント幅も注意

Face = input().split()
rot=input()
dice=Dice(rot,Face)
finFace= Dice.Rotate(rot,Face)
print(finFace[0])

Submission status: Accepted

Solution code:
class Dice:
    def __init__(self):
        self.number = [i for i in range(6)]

    def set_number(self, d0, d1, d2, d3, d4, d5):
        self.number[0] = d0
        self.number[1] = d1
        self.number[2] = d2
        self.number[3] = d3
        self.number[4] = d4
        self.number[5] = d5

    def roll(self, command):
        if   command == "E":
            self.set_number(self.number[3],self.number[1],self.number[0],self.number[5],self.number[4],self.number[2])
        elif command == "N":
            self.set_number(self.number[1],self.number[5],self.number[2],self.number[3],self.number[0],self.number[4])
        elif command == "S":
            self.set_number(self.number[4],self.number[0],self.number[2],self.number[3],self.number[5],self.number[1])
        elif command == "W":
            self.set_number(self.number[2],self.number[1],self.number[5],self.number[0],self.number[4],self.number[3])
        else:
            raise

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




list_face = list(map(int, input().split()))
commands = input()

dice = Dice()
dice.set_number(list_face[0], list_face[1], list_face[2], list_face[3], list_face[4], list_face[5])

for command in commands:
    dice.roll(command)

print(dice.get_top())

Submission status: Accepted

Solution code:
def S(dice):
    a_0=dice[0]
    a_1=dice[1]
    a_4=dice[4]
    a_5=dice[5]
    dice[1]=a_0
    dice[5]=a_1
    dice[4]=a_5
    dice[0]=a_4

def N(dice):
    a_0=dice[0]
    a_1=dice[1]
    a_4=dice[4]
    a_5=dice[5]
    dice[1]=a_5
    dice[5]=a_4
    dice[4]=a_0
    dice[0]=a_1

def W(dice):
    a_0=dice[0]
    a_3=dice[3]
    a_5=dice[5]
    a_2=dice[2]
    dice[0]=a_2
    dice[3]=a_0
    dice[5]=a_3
    dice[2]=a_5

def E(dice):
    a_0=dice[0]
    a_3=dice[3]
    a_5=dice[5]
    a_2=dice[2]
    dice[0]=a_3
    dice[3]=a_5
    dice[5]=a_2
    dice[2]=a_0

dice=list(map(int,input().split()))
command=str(input())

for i in command:
    if i=='S':
        S(dice)
    elif i=='N':
        N(dice)
    elif i=='W':
        W(dice)
    elif i=='E':
        E(dice)
print(dice[0])

Submission status: Accepted

Solution code:
# ITP_11_A
class Dice :
    # クラス変数
    def __init__(self, dice) :
        self.dice = dice
    
    def roll(self, direction):
        tmp = self.dice[:]
        if direction == "N":
            self.dice[0] = tmp[1]
            self.dice[1] = tmp[5]
            self.dice[4] = tmp[0]
            self.dice[5] = tmp[4]
        elif direction == "E":
            self.dice[0] = tmp[3]
            self.dice[2] = tmp[0]
            self.dice[3] = tmp[5]
            self.dice[5] = tmp[2]
        elif direction == "W":
            self.dice[0] = tmp[2]
            self.dice[2] = tmp[5]
            self.dice[3] = tmp[0]
            self.dice[5] = tmp[3]
        else:
            self.dice[0] = tmp[4]
            self.dice[1] = tmp[0]
            self.dice[4] = tmp[5]
            self.dice[5] = tmp[1]
            
    def dice_show(self):
        print(self.dice[0])

dice = Dice(list(map(str, input().split())))

for dire in list(input()):
    dice.roll(dire)
    
dice.dice_show()

Submission status: Accepted

Solution code:
class Dice:
    N = [0, 1, 5, 4]
    S = N[::-1]
    E = [0, 3, 5, 2]
    W = E[::-1]

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

    def toX(self, x):
        data = getattr(self, x)
        self.numbers.append(0)
        for k in range(5):
            i1 = data[k - 1] if k != 0 else 6
            i2 = data[k] if k != 4 else 6
            self.numbers[i1] = self.numbers[i2]
        del self.numbers[6]

dice = Dice([int(i) for i in input().split()])
[dice.toX(d) for d in input()]
print(dice.numbers[0])

Submission status: Accepted

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

for j in range(len(order)) :
  if(order[j] == "S") :
    key = face[4]
    face[4] = face[5]
    face[5] = face[1]
    face[1] = face[0]
    face[0] = key
  elif(order[j] == "N") :
    key = face[1]
    face[1] = face[5]
    face[5] = face[4]
    face[4] = face[0]
    face[0] = key
  elif(order[j] == "E") :
    key = face[3]
    face[3] = face[5]
    face[5] = face[2]
    face[2] = face[0]
    face[0] = key
  else :
    key = face[2]
    face[2] = face[5]
    face[5] = face[3]
    face[3] = face[0]
    face[0] = key

print(face[0])

Submission status: Accepted

Solution code:
from enum import Enum
import sys
import math

#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:
def dice(dice_num,direction):
	for s in direction:
		tmp = dice_num
		if s == "S":
			dice_num = [tmp[4],tmp[0],tmp[2],tmp[3],tmp[5],tmp[1]]	
		elif s == "E":
			dice_num = [tmp[3],tmp[1],tmp[0],tmp[5],tmp[4],tmp[2]]
		elif s == "N":
			dice_num = [tmp[1],tmp[5],tmp[2],tmp[3],tmp[0],tmp[4]]
		elif s == "W":
			dice_num = [tmp[2],tmp[1],tmp[5],tmp[0],tmp[4],tmp[3]]
	return(dice_num[0])

if __name__ == '__main__':
	dice_num = [int(s) for s in input().split()]
	direction = input()

	print(dice(dice_num,direction))

Submission status: Accepted

Solution code:
class Dice:
    def __init__(self):
        self.number = [i for i in range(6)]
        self.tmp = [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 next(self,direction):
        for i in range(6):
            self.tmp[i] = self.number[i]

        if direction == 'E':
            self.setNumber(self.tmp[3], self.tmp[1], self.tmp[0], self.tmp[5], self.tmp[4], self.tmp[2])
        elif direction == 'N':
            self.setNumber(self.tmp[1], self.tmp[5], self.tmp[2], self.tmp[3], self.tmp[0], self.tmp[4])
        elif direction == 'S':
            self.setNumber(self.tmp[4], self.tmp[0], self.tmp[2], self.tmp[3], self.tmp[5], self.tmp[1])
        elif direction == 'W':
            self.setNumber(self.tmp[2], self.tmp[1], self.tmp[5], self.tmp[0], self.tmp[4], self.tmp[3])
    def get_result(self):
        return self.number[0]

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

for str in dire_str:
    dice.next(str)

print(dice.get_result())

Submission status: Accepted

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

    def roll_e(self):
        self.stat[0], self.stat[2], self.stat[5], self.stat[3] = self.stat[3], self.stat[0], self.stat[2], self.stat[5]

    def roll_w(self):
        self.stat[0], self.stat[2], self.stat[5], self.stat[3] = self.stat[2], self.stat[5], self.stat[3], self.stat[0]

    def roll_n(self):
        self.stat[0], self.stat[1], self.stat[5], self.stat[4] = self.stat[1], self.stat[5], self.stat[4], self.stat[0]

    def roll_s(self):
        self.stat[0], self.stat[1], self.stat[5], self.stat[4] = self.stat[4], self.stat[0], self.stat[1], self.stat[5]

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


dice = Dice(input().split())
commands = input()
for command in commands:
    if command == "E":
        dice.roll_e()
    elif command == "W":
        dice.roll_w()
    elif command == "N":
        dice.roll_n()
    elif command == "S":
        dice.roll_s()
print(dice.get_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 roll(self, axis, count=1):
        while count < 0:
            count += 4
        if axis == "X":
            for _ in range(count):
                self.top, self.back, self.bottom, self.front = self.front, self.top, self.back, self.bottom
        elif axis == "Y":
            for _ in range(count):
                self.top, self.right, self.bottom, self.left = self.left, self.top, self.right, self.bottom
        elif axis == "Z":
            for _ in range(count):
                self.front, self.left, self.back, self.right = self.right, self.front, self.left, self.back
        elif axis == "N":
            self.roll("X", 1)
        elif axis == "W":
            self.roll("Y", -1)
        elif axis == "S":
            self.roll("X", -1)
        elif axis == "E":
            self.roll("Y", 1)


labels = [int(c) for c in input().split()]
operations = input()
d = Dice(labels)
for o in operations:
    d.roll(o)
print(d.top)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
#! python3
# diceI.py - サイコロを転がす動きをシミュレートするプログラム

def initDice(numbers): # サイコロオブジェクトに値を入れる
    # サイコロオブジェクトを定義, 配列の数値を、各面にわたす
    dice = {'top': numbers[0], 'bottom': numbers[5], 'front': numbers[1],
            'back': numbers[4], 'right': numbers[2], 'left': numbers[3]}
    return dice

def rollDice(dice, direction): # サイコロを転がしたときの関数
    dice = dice
    if direction == 'N':
        top = dice['front']
        bottom = dice['back']
        front = dice['bottom']
        back = dice['top']
        dice['top'] = top
        dice['bottom'] = bottom
        dice['front'] = front
        dice['back'] = back
    elif direction == 'S':
        top = dice['back']
        bottom = dice['front']
        front = dice['top']
        back = dice['bottom']
        dice['top'] = top
        dice['bottom'] = bottom
        dice['front'] = front
        dice['back'] = back
    elif direction == 'E':
        top = dice['left']
        bottom = dice['right']
        right = dice['top']
        left = dice['bottom']
        dice['top'] = top
        dice['bottom'] = bottom
        dice['right'] = right
        dice['left'] = left
    elif direction == 'W':
        top = dice['right']
        bottom = dice['left']
        right = dice['bottom']
        left = dice['top']
        dice['top'] = top
        dice['bottom'] = bottom
        dice['right'] = right
        dice['left'] = left
    return dice

numbers = [int(i) for i in input().split()]
dice = initDice(numbers)
directions = input()
for direction in directions:
  dice = rollDice(dice, direction)

print(dice['top'])

Submission status: Accepted

Solution code:
class Dice():
  def __init__ (self):
    # 1:ue 2:syomen 3:migi 4:hidari 5:oku 6:shita
    self.position = [0,0,0,0,0,0]
  
  def setNumber (self, num):
    for i,x in enumerate(num):
      self.position[i] = x
    #print(self.position)
      
  def roll(self, roll):
    for i in range(len(roll)):
      s = roll[i:i+1]
      p = self.position
      if s == 'E':
        self.setNumber([p[3], p[1], p[0], p[5], p[4], p[2]])
        #self.position = [p[4], p[2], p[1], p[6], p[5], p[3]]
      elif s == 'W':
        self.setNumber([p[2], p[1], p[5], p[0], p[4], p[3]])
        #self.position = [p[3], p[2], p[6], p[1], p[5], p[4]]
      elif s == 'S':
        self.setNumber([p[4], p[0], p[2], p[3], p[5], p[1]])
        #self.position = [p[5], p[1], p[3], p[4], p[6], p[2]]
      elif s == 'N':
        self.setNumber([p[1], p[5], p[2], p[3], p[0], p[4]])
        #self.position = [p[2], p[6], p[3], p[4], p[1], p[5]]

  def printTop(self):
    print(self.position[0])

d = Dice()

n = list(int(x) for x in input().split())
d.setNumber(n)

r = str(input())

d.roll(r)

d.printTop()

Submission status: Accepted

Solution code:
class Dice:
    def __init__(self,my_label):
        self.top,self.front,self.right,self.left,self.back,self.bottom = [int(x) for x in my_label]

    def Roll(self,i):
        if i == "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
        
        if i =="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
        
        if i =="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
            
        if i =="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

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

        
        
numbers = [int(x) for x in input().split(" ")]
commands = [str(c) for c in input()]

my_label = numbers
dice = Dice(my_label)

for c in commands:
    dice.Roll(c)

dice.Open()

Submission status: Accepted

Solution code:
class dice:
    def __init__(self, t, S, E):
        self.dice = list(map(int, input().split()))
        self.t = t
        self.S = S
        self.E = E
        self.now_dice()
    
    def roll(self, order):
        if order == 'E':
            self.t, self.E = self.W, self.t
        elif order == 'N':
            self.t, self.S = self.S, self.g
        elif order == 'S':
            self.t, self.S = self.N, self.t
        elif order == 'W':
            self.t, self.E = self.E, self.g
        self.now_dice()
    
    def now_dice(self):
        self.N = 7 - self.S
        self.g = 7 - self.t
        self.W = 7 - self.E
        self.now = [self.t, self.S, self.E, self.N, self.W, self.g]
        return self.now

if __name__ == '__main__':
    dice = dice(1, 2, 3)
    order = list(input())
    for v in order:
        dice.roll(v)
    print(dice.dice[dice.t-1])

Submission status: Accepted

Solution code:
#coding: UTF-8
# 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:
class Dice:
    def __init__(self, numbers):
        self.numbers = numbers
        self.number_dict = {1:numbers[0], 2:numbers[1], 3:numbers[2], -3:numbers[3], -2:numbers[4], -1: numbers[5]}
        self.top = 1
        self.front = 2
        self.right = 3

    def move(self, direction):
        if direction == 'N':
            self.top, self.front = self.front, -self.top
        elif direction == 'S':
            self.top, self.front = -self.front, self.top
        elif direction == 'E':
            self.top, self.right = -self.right, self.top
        else:
            self.top, self.right = self.right, -self.top

    def show_number(self):
        print(self.number_dict[self.top])

dice = Dice(list(map(int, input().split())))
move_cmd = input()
for char in move_cmd:
    dice.move(char)
dice.show_number()

Submission status: Accepted

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

Submission status: Accepted

Solution code:
d=list(map(int,input().split()))
t=[d[i] for i in [0,1,5,4]]
y=[d[i] for i in [0,2,5,3]]

for i in input():
    if i == 'N' or i=='S':
        if i=='S':
            t.insert(0,t.pop())
        else:
            t.append(t.pop(0))
        y[0],y[2]=t[0],t[2]
    if i == 'W' or i=='E':
        if i=='E':
            y.insert(0,y.pop())
        else:
            y.append(y.pop(0))
        t[0],t[2]=y[0],y[2]
print(t[0])

Submission status: Accepted

Solution code:
class Dice:
    def __init__(self, labels):
        self.labels = labels
        
    def __str__(self):
        return str(self.labels[0])
    
    def roll_south(self):
        self.labels[0], self.labels[1], self.labels[5], self.labels[4] = self.labels[4], self.labels[0], self.labels[1], self.labels[5]
            
    def roll_east(self):
        self.labels[0], self.labels[2], self.labels[5], self.labels[3] = self.labels[3], self.labels[0], self.labels[2], self.labels[5]
    
    def roll_west(self):
        self.labels[0], self.labels[3], self.labels[5], self.labels[2] = self.labels[2], self.labels[0], self.labels[3], self.labels[5]
    
    def roll_north(self):
        self.labels[0], self.labels[4], self.labels[5], self.labels[1] = self.labels[1], self.labels[0], self.labels[4], self.labels[5]
        
def main():
    labels = list(map(int, input().split()))
    orders = input()
    d = Dice(labels)
    for o in orders:
        if o == 'S':
            d.roll_south()
        elif o == 'E':
            d.roll_east()
        elif o == 'W':
            d.roll_west()
        elif o == 'N':
            d.roll_north()
    print(d)
    
main()

Submission status: Accepted

Solution code:
class Dice:
    def __init__(self):
        self.number = [0]*6
        self.work = [0]*6
        
    def setNumber(self,n0,n1,n2,n3,n4,n5): #Diceの面に与えられた引数の値をセット
        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 lotate(self,st):
        for i in range(len(self.number)):
            self.work[i] = self.number[i]  
        if st == 'E':
            self.setNumber(self.work[3],self.work[1],self.work[0],self.work[5],self.work[4],self.work[2])
        if st == 'N':
            self.setNumber(self.work[1],self.work[5],self.work[2],self.work[3],self.work[0],self.work[4])
        if st == 'W':
            self.setNumber(self.work[2],self.work[1],self.work[5],self.work[0],self.work[4],self.work[3])
        if st == 'S':
            self.setNumber(self.work[4],self.work[0],self.work[2],self.work[3],self.work[5],self.work[1])

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


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

dice = Dice()
dice.setNumber(s[0],s[1],s[2],s[3],s[4],s[5])

request = input()       #命令の入力
for w in request:       #命令の実行
    dice.lotate(w)

result = dice.top()
print(result)

Submission status: Accepted

Solution code:
class Dice:
  def __init__(self, m1, m2, m3, m4, m5, m6):
    self.m1 = m1
    self.m2 = m2
    self.m3 = m3
    self.m4 = m4
    self.m5 = m5
    self.m6 = m6

  def moveDice(self, dir):
    if dir == 'S':
      self.m1, self.m2, self.m6, self.m5 = self.m5, self.m1, self.m2, self.m6
    elif dir == 'N':
      self.m1, self.m2, self.m6, self.m5 = self.m2, self.m6, self.m5, self.m1
    elif dir == 'E':
      self.m1, self.m4, self.m6, self.m3 = self.m4, self.m6, self.m3, self.m1
    elif dir == 'W':
      self.m1, self.m3, self.m6, self.m4 = self.m3, self.m6, self.m4, self.m1

n1, n2, n3, n4, n5, n6 = map(int, input().split())
direct = input()

dice1 = Dice(n1, n2, n3, n4, n5, n6)
for i in range(len(direct)):
  dice1.moveDice(direct[i])

print(dice1.m1)

Submission status: Accepted

Solution code:
class Dice():
    def __init__(self):
        self.number = [i for i in range(6)]
        self.work = [i for i in range(6)]
    
    def set(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 kaiten(self,m):
        for i in range(6):
            self.work[i] = self.number[i]
        if m == 'E':
            self.set(self.work[3],self.work[1],self.work[0],self.work[5],self.work[4],self.work[2])
        elif m == 'N':
            self.set(self.work[1],self.work[5],self.work[2],self.work[3],self.work[0],self.work[4])
        elif m == 'S':
            self.set(self.work[4],self.work[0],self.work[2],self.work[3],self.work[5],self.work[1])
        elif m == 'W':
            self.set(self.work[2],self.work[1],self.work[5],self.work[0],self.work[4],self.work[3])
    
    def top(self):
        return self.number[0]
    
a = Dice()
table = list(map(int,input().split()))
a.set(table[0], table[1], table[2], table[3], table[4], table[5])

m = str(input())
for i in m:
    a.kaiten(i)
    
print("%d"%(a.top()))

Submission status: Accepted

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

    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.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, s, e, w, n, d)
st = input()
for c in st:
    dice.rot(c)
print(dice.u)

Submission status: Accepted

Solution code:
num = list(input().split())
command = list(input())

#コマンドによって位置が変わるnumのインデックス
patterns = {"N":[1,5,2,3,0,4],"S":[4,0,2,3,5,1],"W":[2,1,5,0,4,3],"E":[3,1,0,5,4,2]}

#commandの文字を読み取り、該当するpatternsのvalueを順に取り出して、numの順番を変えていく
for i in command:
    num = [num[j] for j in patterns[i]]

print(num[0])

Submission status: Accepted

Solution code:
class Dice:
        num =[ -1 for x in range(6) ]
        def roll(self, d):
                if   d == "N":
                        b = self.num[0]
                        self.num[0] = self.num[1]
                        self.num[1] = self.num[5]
                        self.num[5] = self.num[4]
                        self.num[4] = b
                elif d == "S":
                        b = self.num[0]
                        self.num[0] = self.num[4]
                        self.num[4] = self.num[5]
                        self.num[5] = self.num[1]
                        self.num[1] = b
                elif d == "W":
                        b = self.num[3]
                        self.num[3] = self.num[0]
                        self.num[0] = self.num[2]
                        self.num[2] = self.num[5]
                        self.num[5] = b
                elif d == "E":
                        b = self.num[3]
                        self.num[3] = self.num[5]
                        self.num[5] = self.num[2]
                        self.num[2] = self.num[0]
                        self.num[0] = b
        
        def __init__(self, lst):
                self.num = lst
        
        def print_num(self, m):
                print(self.num[m])

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

dice = Dice(lst)

for c in buff:
        dice.roll(c)

dice.print_num(0)

Submission status: Accepted

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