Problem:


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

Dice II

Construct a dice from a given sequence of integers in the same way as Dice I.

  You are given integers on the top face and the front face after the dice was rolled in the same way as Dice I. Write a program to print an integer on the right side face.

Input

 In the first line, six integers assigned to faces are given in ascending order of their corresponding labels.
In the second line, the number of questions $q$ is given.

  In the following $q$ lines, $q$ questions are given. Each question consists of two integers on the top face and the front face respectively.

Output

  For each question, print the integer on the right side face.

Constraints

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

The integers are all different

$1 \leq q \leq 24$

Sample Input

1 2 3 4 5 6
3
6 5
1 3
3 2

Sample Output

3
5
6



Sample input:
1 2 3 4 5 6
3
6 5
1 3
3 2


Sample output:
3
5
6

Submission status: Accepted

Solution code:
class Dice:
    def __init__(self, top, front, right, left, back, bottom):
        self.TOP = top
        self.BOTTOM = bottom
        self.FRONT = front
        self.BACK = back
        self.LEFT = left
        self.RIGHT = right
    
    def move(self, direction):
        if direction == "N":
            self.move_N()
        elif direction == "E":
            self.move_E()
        elif direction == "S":
            self.move_S()
        elif direction == "W":
            self.move_W()
        elif direction == "SIDE":
            self.move_SIDE()
        else:
            raise Exception
    
    def move_N(self):
        tmp = self.TOP
        self.TOP = self.FRONT
        self.FRONT = self.BOTTOM
        self.BOTTOM = self.BACK
        self.BACK = tmp

    def move_S(self):
        tmp = self.TOP
        self.TOP = self.BACK
        self.BACK = self.BOTTOM
        self.BOTTOM = self.FRONT
        self.FRONT = tmp
        
    def move_W(self):
        tmp = self.TOP
        self.TOP = self.RIGHT
        self.RIGHT = self.BOTTOM
        self.BOTTOM = self.LEFT
        self.LEFT = tmp

    def move_E(self):
        tmp = self.TOP
        self.TOP = self.LEFT
        self.LEFT = self.BOTTOM
        self.BOTTOM = self.RIGHT
        self.RIGHT = tmp
    
    def move_SIDE(self):
        tmp = self.FRONT
        self.FRONT = self.RIGHT
        self.RIGHT = self.BACK
        self.BACK = self.LEFT
        self.LEFT = tmp

def get_right(t, f):
    dice = Dice(top, front, right, left, back, bottom)
    has_top = False
    for _ in range(4):
        dice.move("N")
        if dice.TOP == t:
            has_top = True
            break
    if not has_top:
        for _ in range(4):
            dice.move("E")
            if dice.TOP == t:
                has_top = True
                break
    for _ in range(4):
        dice.move("SIDE")
        if dice.FRONT == f:
            return dice.RIGHT
    
top, front, right, left, back, bottom = map(int,input().split())
dice = Dice(top, front, right, left, back, bottom)
n = int(input())
for _ in range(n):
    t, f = map(int, input().split())
    l = None
    if top == t and front == f:
        r = right
    else:
        r = get_right(t, f)
    print(r)

Submission status: Accepted

Solution code:
d=input().split()
for _ in range(int(input())):
 t, f =[d.index(s)for s in input().split()]
 n = [(1,2,4,3,1),(0,3,5,2,0),(0,1,5,4,0),(1,0,4,5,1),(0,2,5,3,0),(1,3,4,2,1)][t]
 print(d[n[n.index(f)+1]])

Submission status: Accepted

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

    def south_direction(self):
        front = self.top
        bottom = self.front
        back = self.bottom
        top = self.back
        right = self.right
        left = self.left
        
        self.top = top
        self.front = front
        self.bottom = bottom
        self.back = back
        self.right = right
        self.left = left

    def north_direction(self):
        back = self.top
        top = self.front
        front = self.bottom
        bottom = self.back
        right = self.right
        left = self.left
        
        self.top = top
        self.front = front
        self.bottom = bottom
        self.back = back
        self.right = right
        self.left = left

    def east_direction(self):
        right = self.top
        front = self.front
        left = self.bottom
        back = self.back
        bottom = self.right
        top = self.left
        
        self.top = top
        self.front = front
        self.bottom = bottom
        self.back = back
        self.right = right
        self.left = left
        
    def west_direction(self):
        left = self.top
        front = self.front
        right = self.bottom
        back = self.back
        top = self.right
        bottom = self.left
        
        self.top = top
        self.front = front
        self.bottom = bottom
        self.back = back
        self.right = right
        self.left = left
    
    def clockwise_rotate(self):
        top = self.top
        left = self.front
        bottom = self.bottom
        right = self.back
        front = self.right
        back = self.left
        
        self.top = top
        self.front = front
        self.bottom = bottom
        self.back = back
        self.right = right
        self.left = left
        
    
    def print_top(self):
        print(self.top)

    def judge_right(self, top, front):
        while True:
            if self.top == top and self.front == front:
                print(self.right)
                break
            elif top==self.front:
                self.north_direction()
            elif top == self.left:
                self.east_direction()
            elif top == self.back:
                self.south_direction()
            elif top == self.right:
                self.west_direction()
            elif top == self.bottom:
                self.north_direction()
                self.north_direction()
        
            elif front == self.front:
                pass
            elif front == self.left:
                self.clockwise_rotate()
                self.clockwise_rotate()
                self.clockwise_rotate()
            elif front == self.back:
                self.clockwise_rotate()
                self.clockwise_rotate()
            elif front == self.right:
                self.clockwise_rotate()
    
num = list(map(int,input().split()))
rep=int(input())
d = Dice(num)

for i in range(rep):
    top, front = map(int, input().split())
    d.judge_right(top, front)

Submission status: Accepted

Solution code:
sokumen={1:[2,3,5,4,2],2:[6,3,1,4,6],3:[2,6,5,1,2],4:[2,1,5,6,2],5:[1,3,6,4,1],6:[5,3,2,4,5]}
number=list(map(int,input().split()))
q=int(input())
for _ in range(q):
    u,f=map(int,input().split())
    u=number.index(u)+1
    f=number.index(f)+1
    ans=sokumen[u][sokumen[u].index(f)+1]
    print(number[ans-1])

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 setnum(self,s):
        self.number = s

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

    def Qright(self,up,flont,num):
        uf = (up,flont)
        if uf == (num[1],num[2]) or uf ==(num[2],num[4]) or uf ==(num[4],num[3]) or uf ==(num[3],num[1]):
            ans = num[0]
        elif uf == (num[0],num[3]) or uf ==(num[3],num[5]) or uf ==(num[5],num[2]) or uf ==(num[2],num[0]):
            ans = num[1]
        elif uf == (num[0],num[1]) or uf ==(num[1],num[5]) or uf ==(num[5],num[4]) or uf ==(num[4],num[0]):
            ans = num[2]
        elif uf == (num[0],num[4]) or uf ==(num[4],num[5]) or uf ==(num[5],num[1]) or uf ==(num[1],num[0]):
            ans = num[3]
        elif uf == (num[0],num[2]) or uf ==(num[2],num[5]) or uf ==(num[5],num[3]) or uf ==(num[3],num[0]):
            ans = num[4]
        elif uf == (num[1],num[3]) or uf ==(num[3],num[4]) or uf ==(num[4],num[2]) or uf ==(num[2],num[1]):
            ans = num[5]
        print(ans)


num = list(map(int,input().split()))
#kaitenn = input()
q = int(input())
dice = dice()
dice.setnum(num)
for i in range(q):
    up,flont = map(int,input().split())
    dice.Qright(up,flont,num)
#print(dice.number[0])

Submission status: Accepted

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

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

    def get_right(self):
        right_list =[
            (1, 2, 4, 3), #0
            (0, 3, 5, 2), #1
            (0, 1, 5, 4), #2
            (0, 4, 5, 1), #3
            (0, 2, 5, 3), #4
            (1, 3, 4, 2)  #5
        ]

        for i in range(6):
            if self.dice[i] == self.top:
                for j in range(4):
                    if self.dice[right_list[i][j]] == self.front:
                        print(self.dice[right_list[i][j-3]])

for i in range(q):
    top, front = map(int, input().split())
    dice_right = Dice(dice, top, front)
    dice_right.get_right()

Submission status: Accepted

Solution code:
from copy import deepcopy
from copy import copy

class Dice:
    def __init__(self, labels):
        self.surface = {x: labels[x-1] for x in range(1, 6+1)}
    def move_towards(self, direction):
        if direction == 'N':
            self._move(1, 2, 6, 5)
        elif direction == 'S':
            self._move(1, 5, 6, 2)
        elif direction == 'E':
            self._move(1, 4, 6, 3)
        elif direction == 'W':
            self._move(1, 3, 6, 4)
    def get_upper(self):
        return self.surface[1]
    def _move(self, i, j, k, l):
        temp_label = self.surface[i]
        self.surface[i] = self.surface[j]
        self.surface[j] = self.surface[k]
        self.surface[k] = self.surface[l]
        self.surface[l] = temp_label
    
    def find_pattern(self, pattern):
        dice = deepcopy(self)
        if dice.surface[1] == pattern[0] and dice.surface[2] == pattern[1]:
            return dice.surface[3]
        
        pattern_tested = {'original': dice.surface}
        moves = ['N', 'S', 'E', 'W']
        
        def find(dice, moves):
            next_moves = []
            for move in moves:
                if len(move) == 1:
                    start = 'original'
                else:
                    start = move[:-1]
                    
                dice.surface =pattern_tested[start]
                dice.move_towards(move[-1])
                
                if dice.surface[1] == pattern[0] and dice.surface[2] == pattern[1]:
                    right_label = dice.surface[3]
                    return right_label
                else:
                    move_tested = move
                    pattern_tested[move_tested] = copy(dice.surface)
                    next_moves.extend([move+'N', move+'S', move+'E', move+'W'])
            return find(dice, next_moves)
                
        return find(dice, moves)
    
labels = list(map(int, input().split()))
num_questions = int(input())
questions = [list(map(int, input().split())) for _ in range(num_questions)]
dice = Dice(labels)
results = []

for question in questions:
    right_label = dice.find_pattern(question)
    results.append(right_label)

for result in results:
    print(result)

Submission status: Accepted

Solution code:
#coding: utf-8

tfr = ((1, 2, 4, 3), (0, 3, 5, 2), (0, 1, 5, 4),
(0, 4, 5, 1), (0, 2, 5, 3), (1, 3, 4, 2))

label = list(map(int, input().split()))
q = int(input())
for i in range(q):
    t, f = map(int, input().split())
    idxt = label.index(t)
    idxf = label.index(f)
    idxr = tfr[idxt].index(idxf) + 1
    if idxr == 4:
        idxr = 0
    print(label[tfr[idxt][idxr]])

Submission status: Accepted

Solution code:
class Dice:
    def __init__(self, default = [1, 2, 3, 4, 5, 6]):
        self.d = default

    def e(self):
        self.d[0], self.d[2], self.d[3], self.d[5] = self.d[3], self.d[0], self.d[5], self.d[2]

    def w(self):
        self.d[0], self.d[2], self.d[3], self.d[5] = self.d[2], self.d[5], self.d[0], self.d[3]

    def n(self):
        self.d[0], self.d[1], self.d[4], self.d[5] = self.d[1], self.d[5], self.d[0], self.d[4]

    def s(self):
        self.d[0], self.d[1], self.d[4], self.d[5] = self.d[4], self.d[0], self.d[5], self.d[1]

    def r(self):
        self.d[1], self.d[2], self.d[3], self.d[4] = self.d[3], self.d[1], self.d[4], self.d[2]

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

    def forward(self):
        return self.d[1]

    def right(self):
        return self.d[2]


def main():
    dice = Dice([int(i) for i in input().split()])
    n = int(input())
    for i in range(n):
        t, f = map(int, input().split())
        for i in range(4):
            if dice.top() == t:
                break
            dice.e()
        else:
            for j in range(3):
                if dice.top() == t:
                    break
                dice.s()

        for i in range(3):
            if dice.forward() == f:
                break
            dice.r()

        print(dice.right())


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
class Dice:
    #f[]はUSEWNDの順，添字はU:0,S:1,E:2,W:3,N:4,D:5
    def __init__(self,l):
        self.f=l
        
    def __str__(self):
        l=self.f
        s=f'[U:{l[0]},S:{l[1]},E:{l[2]},W:{l[3]},N:{l[4]},D:{l[5]}]'
        return(s)
       
    def roll(self,c):
        if c=='N':
            ni=[1,5,2,3,0,4]
        elif c=='S':
            ni=[4,0,2,3,5,1]
        elif c=='E':
            ni=[3,1,0,5,4,2]
        elif c=='W':
            ni=[2,1,5,0,4,3]
        self.f=[self.f[j] for j in ni]
    
    def rotate(self,r):
        if r==+1: #Uから見て反時計(西)回り
            ni=[0,3,1,4,2,5]
        elif r==-1: #Uから見て時計(東)周り
            ni=[0,2,4,1,3,5]
        self.f=[self.f[j] for j in ni]

    def patterns(self):
        fs=[]
        for i in range(6):
            if i%2==0:
                self.roll('N')
            else:
                self.roll('E')
            for j in range(4):
                self.rotate(+1)
                fs.append(self.f)
        return fs
        
    def lookEast(self,l):
        for f in self.patterns():
            if f[0]==l[0] and f[1]==l[1]:
                return f[2]

d=Dice(list(map(int,input().split())))
q=int(input())
for i in range(q):
    print(d.lookEast(list(map(int,input().split()))))

Submission status: Accepted

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


kaisuu = int(input())

lastlist = []
frlist = []
for i in range(kaisuu):
  up,front = list(map(int,input().split()))
  if up == dice[0] :
    frlist = [1,2,4,3,1]
  if up == dice[1]:
    frlist = [0,3,5,2,0]
  if up == dice[2]:
    frlist = [0,1,5,4,0]
  if up == dice[3]:
    frlist = [0,4,5,1,0]
  if up == dice[4]:
    frlist = [0,2,5,3,0]
  if up == dice[5] :
    frlist = [1,3,4,2,1]
 
  k = dice.index(int(front))
  for n in frlist[0:4] :
    if n == k :
      l = frlist.index(int(n))
      m = l + 1
  lastlist.append(dice[frlist[m]])
for g in lastlist :
  print(g)

Submission status: Accepted

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

class Dice():
    def __init__(self, t, s, e, w, n, b):
        self.a = [t, s, e, w, n, b]
    
    def shake(self, me):
        if me == 'S':
            self.b = [self.a[int(i)] for i in '402351']
            self.a = self.b
        elif me == 'N':
            self.b = [self.a[int(i)] for i in '152304']
            self.a = self.b
        if me == 'W':
            self.b = [self.a[int(i)] for i in '215043']
            self.a = self.b
        if me == 'E':
            self.b = [self.a[int(i)] for i in '310542']
            self.a = self.b  
    def get(self, dir):
        if dir == 't': return self.a[0]
        elif dir == 'f': return self.a[1]
        elif dir == 'e': return self.a[2]
        elif dir == 'w': return self.a[3]
        else: print('input err', dir)

d = Dice(*num)
for i in range(q):
    u, f = map(int, input().split())
    for j in range(50):
        if d.get('t') == u and d.get('f') == f:
            print(d.get('e'))
            break
        elif d.get('w') == f or d.get('e') == f or d.get('f') == f:
            d.shake('W')
        else:
            d.shake('S')

Submission status: Accepted

Solution code:
#
class Dice:
    def __init__(self,list):
        self.list = []
        for i in range(6):
            self.list.append(list[i])

    def rotate(self,dir):
        if dir == "N":
            self.list[0], self.list[1], self.list[5], self.list[4] = self.list[1], self.list[5], self.list[4], self.list[0]
        elif dir == "S":
            self.list[0], self.list[4], self.list[5], self.list[1] = self.list[4], self.list[5], self.list[1], self.list[0]
        elif dir == "W":
            self.list[0], self.list[3], self.list[5], self.list[2] = self.list[2], self.list[0], self.list[3], self.list[5]
        elif dir == "E":
            self.list[0], self.list[3], self.list[5], self.list[2] = self.list[3], self.list[5], self.list[2], self.list[0]
        elif dir == "H":
            self.list[1], self.list[2], self.list[4], self.list[3] = self.list[2], self.list[4], self.list[3], self.list[1]
        elif dir =="V":
            self.list[0], self.list[3], self.list[5], self.list[2] = self.list[3], self.list[5], self.list[2], self.list[0]
        else:
            pass

    def show(self):
        print("D:{}".format(repr(self.list)))

    def isface(self,f):
        if f in self.list:
            return True
        else:
            return False

    def matchone(self, f):
        if self.isface(f) == False:
            return False
        if f == self.list[0]:
            pass
        elif f == self.list[1]:
            self.rotate("N")
        elif f == self.list[2]:
            self.rotate("W")
        elif f == self.list[3]:
            self.rotate("E")
        elif f == self.list[4]:
            self.rotate("S")
        else:
            self.rotate("N")
            self.rotate("N")
        return True

    def matchtwo(self, f):
        if self.isface(f) == False:
            return False
        if self.list[1] ==f:
            return True
        for i in range(3):
            self.rotate("H")
            if self.list[1] ==f:
                return True
        return False


l = [ int(x) for x in input().split()]
dice = Dice(l)
num = int(input())

for i in range(num):
    one, two = [int(x) for x in input().split()]
    dice.matchone(one)
    #dice.show()
    dice.matchtwo(two)
    #dice.show()
    print(dice.list[2])

Submission status: Accepted

Solution code:
class Dice:
    val=[]
    def __init__(self, lst):
        self.val.append(lst[0])
        self.val.append(lst[1])
        self.val.append(lst[2])
        self.val.append(lst[3])
        self.val.append(lst[4])
        self.val.append(lst[5])

    def rotate(self,dir):
        if dir=="N":
            tmp=self.val[0]
            self.val[0]=self.val[1]
            self.val[1]=self.val[5]
            self.val[5]=self.val[4]
            self.val[4]=tmp
        if dir=="E":
            tmp=self.val[0]
            self.val[0]=self.val[3]
            self.val[3]=self.val[5]
            self.val[5]=self.val[2]
            self.val[2]=tmp
        if dir=="S":
            tmp=self.val[0]
            self.val[0]=self.val[4]
            self.val[4]=self.val[5]
            self.val[5]=self.val[1]
            self.val[1]=tmp
        if dir=="W":
            tmp=self.val[0]
            self.val[0]=self.val[2]
            self.val[2]=self.val[5]
            self.val[5]=self.val[3]
            self.val[3]=tmp

def int_to_dir(n):
    if n==0:
        return "N"
    if n==1:
        return "E"
    if n==2:
        return "S"
    if n==3:
        return "W"
    

x = list(map(int,input().split()))
q = int(input())

D = Dice(x)

import random 

for i in range(q):
    a,b=map(int,input().split())
    count=0
    while True:
        D.rotate(int_to_dir(random.randint(0,4)))
        #count+=1
        if D.val[0]==a and D.val[1]==b:
            
            print(D.val[2])
            break

Submission status: Accepted

Solution code:

def dice_r(u,f):
	if u == 1:
		if f == 2:
			r = 3
		if f == 3:
			r = 5
		if f == 5:
			r = 4
		if f == 4:
			r = 2
	if u == 2:
		if f == 1:
			r = 4
		if f == 4:
			r = 6
		if f == 6:
			r = 3
		if f == 3:
			r = 1
	if u == 3:
		if f == 1:
			r = 2
		if f == 2:
			r = 6
		if f == 6:
			r = 5
		if f == 5:
			r = 1
	if u == 4:
		if f == 1:
			r = 5
		if f == 5:
			r = 6
		if f == 6:
			r = 2
		if f == 2:
			r = 1
	if u == 5:
		if f == 1:
			r = 3
		if f == 3:
			r = 6
		if f == 6:
			r = 4
		if f == 4:
			r = 1
	if u == 6:
		if f == 2:
			r = 4
		if f == 4:
			r = 5
		if f == 5:
			r = 3
		if f == 3:
			r = 2
	return r
		
n = list(map(int,input().split()))
q = int(input())
for i in range(q):
	a,b = map(int,input().split())
	u = n.index(a) +1
	f = n.index(b) +1
	c = dice_r(u,f)
	ans = n[c-1]
	print(ans)

Submission status: Accepted

Solution code:
def test():

	faces = list(map(int,input().split()))
	n = int(input())

	for i in range(n):

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

		top = given_face[0]
		front = given_face[1]

		if (top == faces[1] and front == faces[2]) or (top == faces[2] and front == faces[4]) or (top == faces[4] and front == faces[3]) or (top == faces[3] and front == faces[1]):
			print(f"{faces[0]}")
		elif (top == faces[0] and front == faces[3]) or (top == faces[3] and front == faces[5]) or (top == faces[5] and front == faces[2]) or (top == faces[2] and front == faces[0]):
			print(f"{faces[1]}")
		elif (top == faces[0] and front == faces[1]) or (top == faces[1] and front == faces[5]) or (top == faces[5] and front == faces[4]) or (top == faces[4] and front == faces[0]):
			print(f"{faces[2]}")
		elif (top == faces[0] and front == faces[4]) or (top == faces[4] and front == faces[5]) or (top == faces[5] and front == faces[1]) or (top == faces[1] and front == faces[0]):
			print(f"{faces[3]}")
		elif (top == faces[0] and front == faces[2]) or (top == faces[2] and front == faces[5]) or (top == faces[5] and front == faces[3]) or (top == faces[3] and front == faces[0]):
			print(f"{faces[4]}")
		elif (top == faces[1] and front == faces[3]) or (top == faces[3] and front == faces[4]) or (top == faces[4] and front == faces[2]) or (top == faces[2] and front == faces[1]):
			print(f"{faces[5]}")

if __name__ == "__main__":
	test()

Submission status: Accepted

Solution code:
class dice:
    def __init__(self,label):
        self.top, self.front, self.right, self.left, self.rear, self.bottom \
                = label
  
    def roll(self,op):
        if   op=='N': self.top, self.front, self.bottom, self.rear = \
                                self.front, self.bottom, self.rear , self.top
        elif op=='E': self.top, self.left , self.bottom, self.right = \
                                self.left , self.bottom, self.right, self.top
        elif op=='W': self.top, self.right, self.bottom, self.left = \
                                self.right, self.bottom, self.left , self.top
        elif op=='S': self.top, self.rear , self.bottom, self.front = \
                                self.rear , self.bottom, self.front, self.top
  
    def print_top(self): print(self.top)
    def print_right(self): print(self.right)
  
    def get_label(self):
        return [self.top, self.front, self.right, self.left, self.rear, self.bottom]
   
label = list(map(int,input().split()))
d = dice(label)
n = int(input())
for i in range(n):
    top_front = [int(x) for x in input().split()]
    for op in 'EEENEEENEEESEEESEEENEEEN':
        if d.get_label()[:2] == top_front:
            d.print_right()
            break
        d.roll(op)

Submission status: Accepted

Solution code:
#!/usr/bin/env python3
import sys
import copy
line = sys.stdin.readline() 
line = line.rstrip('\r\n')
face = line.split()

line = sys.stdin.readline() 

while(True):
    line = sys.stdin.readline() 
    if not line:
        break
    line = line.rstrip('\r\n')
    tar = line.split()
    
    for i in range(5):
        if face[1] == tar[1]:
            break
        face_old = copy.deepcopy(face)
        face[0] = face_old[1]
        face[1] = face_old[5]
        face[2] = face_old[2]
        face[3] = face_old[3]
        face[4] = face_old[0]
        face[5] = face_old[4]
    else:
        face_old = copy.deepcopy(face)
        face[0] = face_old[3]
        face[1] = face_old[1]
        face[2] = face_old[0]
        face[3] = face_old[5]
        face[4] = face_old[4]
        face[5] = face_old[2]
    for i in range(5):
        if face[1] == tar[1]:
            break
        face_old = copy.deepcopy(face)
        face[0] = face_old[1]
        face[1] = face_old[5]
        face[2] = face_old[2]
        face[3] = face_old[3]
        face[4] = face_old[0]
        face[5] = face_old[4]
    for i in range(5):
        if face[0] == tar[0]:
            break
        face_old = copy.deepcopy(face)
        face[0] = face_old[3]
        face[1] = face_old[1]
        face[2] = face_old[0]
        face[3] = face_old[5]
        face[4] = face_old[4]
        face[5] = face_old[2]
    print(face[2])

Submission status: Accepted

Solution code:
#ITP1_11_A

def west(d):
	tmp=d[4]
	d[4]=d[1]
	d[1]=d[3]
	d[3]=d[6]
	d[6]=tmp

def east(d):
	tmp=d[4]
	d[4]=d[6]
	d[6]=d[3]
	d[3]=d[1]
	d[1]=tmp

def north(d):
	tmp=d[1]
	d[1]=d[2]
	d[2]=d[6]
	d[6]=d[5]
	d[5]=tmp

def south(d):
	tmp=d[1]
	d[1]=d[5]
	d[5]=d[6]
	d[6]=d[2]
	d[2]=tmp

def spin(d):
	tmp=d[2]
	d[2]=d[3]
	d[3]=d[5]
	d[5]=d[4]
	d[4]=tmp

def kaiten(d, op):
	if   op == "W": west(d)
	elif op == "E": east(d)
	elif op == "N": north(d)
	elif op == "S": south(d)

def inputDice():
	return list(map(int,("-1 "+input()).split()))

def solveB(d,d1,d2):
	for op in list("NWWWN-"):
		for i in range(4):
			if(d[1]==d1 and d[2]==d2):
				return d[3]
			spin(d)
		kaiten(d,op)
	return None

d=inputDice()
solveB(d,1,2)

for i in range(int(input())):
	d1,d2=map(int,input().split())
	print(solveB(d,d1,d2))

Submission status: Accepted

Solution code:
import random

class dice:
  def __init__(self,dice_number_list):
    self.top,self.front,self.right,self.left,self.rear,self.bottom = dice_number_list
    
  def roll(self,op):
    if   op=='N': 
      self.top, self.front, self.bottom, self.rear = \
      self.front, self.bottom, self.rear , self.top
    elif op=='E':
      self.top, self.left , self.bottom, self.right = \
      self.left , self.bottom, self.right, self.top
    elif op=='W': 
      self.top, self.right, self.bottom, self.left = \
      self.right, self.bottom, self.left , self.top
    elif op=='S': 
      self.top, self.rear , self.bottom, self.front = \
      self.rear , self.bottom, self.front, self.top
           
  def print_top(self):
    print(self.top)
  def print_right(self):
    print(self.right)
    
  def get_label(self):
    return([self.top, self.front, self.right, self.left, self.rear, self.bottom])
    
dice_number_list = list(map(int,input().split()))
d = dice(dice_number_list)

#全パターン24通りの取得
all_dice_number_list=[]
for i in range(10000):
  d.roll(random.choice("NEWS"))
  if d.get_label() not in all_dice_number_list:
    all_dice_number_list.append(d.get_label())
  if len(all_dice_number_list) == 24:
    break

#print(all_dice_number_list)

n=int(input())
for i in range(n):
  top,front = list(map(int,input().split()))
  for dice_list in all_dice_number_list:
    #print(dice_list)
    if dice_list[0]==top and dice_list[1]==front:
      print(dice_list[2]) #rightの面取得

Submission status: Accepted

Solution code:

d=input().split()
for _ in range(int(input())):
 t,f=[d.index(s)for s in input().split()]
 n=[(1,2,4,3,1),(0,3,5,2,0),(0,1,5,4,0),(1,0,4,5,1),(0,2,5,3,0),(1,3,4,2,1)][t]
 print(d[n[n.index(f)+1]])

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)]
        self.order = 'NNNNWNNNWNNNENNNENNNWNNN'
 
    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 query(self,top_num,front_num):
 
        self.save_data = [i for i in range(6)]
        #元の値の保存
        for i in range(len(self.number)):
            self.save_data[i] = self.number[i]
 
        ret = -1;
 
        for i in range(len(self.order)):
            self.roll(self.order[i])
            if self.number[0] == top_num and self.number[1] == front_num:
                ret = self.number[2]
                break
 
        #元の値の復元
        for i in range(len(self.number)):
            self.number[i] = self.save_data[i]
 
        return ret;
 
 
 
 
dice = Dice()
table = list(map(int,input().split()))
dice.setNumber(table[0], table[1], table[2], table[3], table[4], table[5])
 
num_query = int(input())
for loop in range(num_query):
    top_num,front_num = map(int,input().split())
    print("%d"%(dice.query(top_num, front_num)))

Submission status: Accepted

Solution code:
class dice:
    def __init__(self,label):
        self.top, self.front, self.right, self.left, self.rear, self.bottom \
                = label
  
    def roll(self,op):
        if   op=='N': self.top, self.front, self.bottom, self.rear = \
                                self.front, self.bottom, self.rear , self.top
        elif op=='E': self.top, self.left , self.bottom, self.right = \
                                self.left , self.bottom, self.right, self.top
        elif op=='W': self.top, self.right, self.bottom, self.left = \
                                self.right, self.bottom, self.left , self.top
        elif op=='S': self.top, self.rear , self.bottom, self.front = \
                                self.rear , self.bottom, self.front, self.top
  
    def print_top(self): print(self.top)
    def print_right(self): print(self.right)
  
    def get_label(self):
        return [self.top, self.front, self.right, self.left, self.rear, self.bottom]

label = list(map(int,input().split()))
d = dice(label)
q = int(input())
for _ in range(q):
    top_front = [int(x) for x in input().split()]
    for op in 'EEENEEENEEESEEESEEENEEEN':
        if d.get_label()[:2] == top_front:
            d.print_right()
            break
        d.roll(op)