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, d1, d2, d3, d4, d5, d6):
        self.d1 = d1
        self.d2 = d2
        self.d3 = d3
        self.d4 = d4
        self.d5 = d5
        self.d6 = d6
 
    def output(self, a, b):
        if (a == self.d1 and b == self.d2) or (a == self.d2 and b == self.d6) \
         or (a == self.d6 and b == self.d5) or (a == self.d5 and b == self.d1):
            print(self.d3)
        elif (a == self.d2 and b == self.d1) or (a == self.d6 and b == self.d2) \
         or (a == self.d5 and b == self.d6) or (a == self.d1 and b == self.d5):
            print(self.d4)
        elif (a == self.d1 and b == self.d3) or (a == self.d3 and b == self.d6) \
         or (a == self.d6 and b == self.d4) or (a == self.d4 and b == self.d1):
            print(self.d5)
        elif (a == self.d3 and b == self.d1) or (a == self.d6 and b == self.d3) \
         or (a == self.d4 and b == self.d6) or (a == self.d1 and b == self.d4):
            print(self.d2)
        elif (a == self.d2 and b == self.d3) or (a == self.d3 and b == self.d5) \
         or (a == self.d5 and b == self.d4) or (a == self.d4 and b == self.d2):
            print(self.d1)
        elif (a == self.d3 and b == self.d2) or (a == self.d5 and b == self.d3) \
         or (a == self.d4 and b == self.d5) or (a == self.d2 and b == self.d4):
            print(self.d6)  

d1, d2, d3, d4, d5, d6 = map(int, input().split())
dice = Dice(d1, d2, d3, d4, d5, d6)
n = int(input())
for _ in range(n):
    a, b = map(int, input().split())
    dice.output(a, b)

Submission status: Accepted

Solution code:
import copy


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

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

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

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

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

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

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

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

    def adjust_top(self, top: int):
        for _ in range(4):
            if self.top() is top:
                break
            self.roll_e()
        for _ in range(4):
            if self.top() is top:
                break
            self.roll_s()

    def adjust_front(self, front: int):
        for _ in range(4):
            if self.front() is front:
                break
            self.turn_right()

    def front(self):
        return self.__eyes[1]

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


def resolve():
    eyes = list(map(int, input().split()))
    n = int(input())

    for _ in range(n):
        dice = Dice(eyes)
        top, front = map(int, input().split())
        dice.adjust_top(top)
        dice.adjust_front(front)
        print(dice.right())


resolve()

Submission status: Accepted

Solution code:
dice = [int(i) for i in input().split()]
n = int(input())
for _ in range(n):
    face = list(map(int, input().split()))
    if face in [[dice[0], dice[1]], [dice[1], dice[5]], [dice[5], dice[4]], [dice[4], dice[0]]]:
        print(dice[2])
    elif face in [[dice[0], dice[2]], [dice[2], dice[5]], [dice[5], dice[3]], [dice[3], dice[0]]]:
        print(dice[4])
    elif face in [[dice[0], dice[4]], [dice[4], dice[5]], [dice[5], dice[1]], [dice[1], dice[0]]]:
        print(dice[3])
    elif face in [[dice[0], dice[3]], [dice[3], dice[5]], [dice[5], dice[2]], [dice[2], dice[0]]]:
        print(dice[1])
    elif face in [[dice[1], dice[2]], [dice[2], dice[4]], [dice[4], dice[3]], [dice[3], dice[1]]]:
        print(dice[0])
    elif face in [[dice[1], dice[3]], [dice[3], dice[4]], [dice[4], dice[2]], [dice[2], dice[1]]]:
        print(dice[5])

Submission status: Accepted

Solution code:
class Dice():
    #0:上面、1:前面、2:側面(見える方)、3:側面(裏側)、4:背面、5:底面
    def __init__(self,numlist):
        self.lst=numlist
    
    def roll(self,direction):
        for x in direction:
            if x=="S" : self.lst=[self.lst[4],self.lst[0],self.lst[2],self.lst[3],self.lst[5],self.lst[1]]
            elif x=="N" : self.lst=[self.lst[1],self.lst[5],self.lst[2],self.lst[3],self.lst[0],self.lst[4]]
            elif x=="W" : self.lst=[self.lst[2],self.lst[1],self.lst[5],self.lst[0],self.lst[4],self.lst[3]]
            elif x=="E" : self.lst=[self.lst[3],self.lst[1],self.lst[0],self.lst[5],self.lst[4],self.lst[2]]        
    
    def dice_set_make(self):
        self.dice_set=[]
        for x in ["","W","WW","WWW","SE","SW"]:
            self.work=Dice(self.lst[:])
            self.work.roll(x)
            self.dice_set.append(self.work.lst)
            for _ in range(3):
                self.work.roll("S")
                self.dice_set.append(self.work.lst)
        

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

d1=Dice(lst)
d1.dice_set_make()
dice_set=d1.dice_set

for _ in range(q):
    a,b=map(int,input().split())
    for x in dice_set:
        if x[0]==a and x[1]==b:
            print(x[2])
            break

Submission status: Accepted

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


A = input().split()
dice = Dice(A[0], A[1], A[2], A[3], A[4], A[5])
for _ in range(int(input())):
    tp, fwd = input().split()
    print(dice.rs(dice.nbrs.index(tp), dice.nbrs.index(fwd)))

Submission status: Accepted

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

        self.n_list = [0, self.a, self.b, self.c, self.d, self.e, self.f]

    def is_right_surface(self, top, front):
        swapped = False
        """
        print(f"{top=}")
        print(f"{front=}")
        print(f"{self.n_list.index(top)=}")
        print(f"{self.n_list.index(front)=}")
        """
        if self.n_list.index(top) > self.n_list.index(front):
            tmp = front
            front = top
            top = tmp
            swapped = True

        if self.n_list.index(top) == 1 and self.n_list.index(front) == 2:
            return self.c, self.d, swapped
        if self.n_list.index(top) == 1 and self.n_list.index(front) == 3:
            return self.e, self.b, swapped
        if self.n_list.index(top) == 1 and self.n_list.index(front) == 4:
            return self.b, self.e, swapped
        if self.n_list.index(top) == 1 and self.n_list.index(front) == 5:
            return self.d, self.c, swapped
        if self.n_list.index(top) == 2 and self.n_list.index(front) == 3:
            return self.a, self.f, swapped
        if self.n_list.index(top) == 2 and self.n_list.index(front) == 4:
            return self.f, self.a, swapped
        if self.n_list.index(top) == 2 and self.n_list.index(front) == 6:
            return self.c, self.d, swapped
        if self.n_list.index(top) == 3 and self.n_list.index(front) == 5:
            return self.a, self.f, swapped
        if self.n_list.index(top) == 3 and self.n_list.index(front) == 6:
            return self.e, self.b, swapped
        if self.n_list.index(top) == 4 and self.n_list.index(front) == 5:
            return self.f, self.a, swapped
        if self.n_list.index(top) == 4 and self.n_list.index(front) == 6:
            return self.b, self.e, swapped
        if self.n_list.index(top) == 5 and self.n_list.index(front) == 6:
            return self.d, self.c, swapped

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

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

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

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

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


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

n = int(input())
for i in range(n):
    x, y = map(int, input().split())
    right, left, is_swap = dice.is_right_surface(x, y)
    if is_swap:
        print(left)
    else:
        print(right)

Submission status: Accepted

Solution code:
class Dice():
    def __init__(self, spots):
        self.spots = [spots[i] for i in range(6)]
    
    def roll(self, direction):
        if direction == 0:
            self.spots = [self.spots[i] for i in [1, 5, 2, 3, 0, 4]]
        elif direction == 1:
            self.spots = [self.spots[i] for i in [3, 1, 0, 5, 4, 2]]
        elif direction == 2:
            self.spots = [self.spots[i] for i in [4, 0, 2, 3, 5, 1]]
        elif direction == 3:
            self.spots = [self.spots[i] for i in [2, 1, 5, 0, 4, 3]]
            
first_state = list(map(int, input().split()))
q = int(input())

for _ in range(q):
    my_dice = Dice(first_state)
    a, b = map(int, input().split())

    if b == my_dice.spots[0]:
        my_dice.roll(2)
    elif b == my_dice.spots[1]:
        pass
    elif b == my_dice.spots[2]:
        my_dice.roll(3)
        my_dice.roll(2)
    elif b == my_dice.spots[3]:
        my_dice.roll(1)
        my_dice.roll(2)
    elif b == my_dice.spots[4]:
        my_dice.roll(2)
        my_dice.roll(2)
    elif b == my_dice.spots[5]:
        my_dice.roll(0)
    
    if a == my_dice.spots[0]:
        pass
    elif a == my_dice.spots[2]:
        my_dice.roll(3)
    elif a == my_dice.spots[3]:
        my_dice.roll(1)
    elif a == my_dice.spots[5]:
        my_dice.roll(1)
        my_dice.roll(1)
        
    print(my_dice.spots[2])

Submission status: Accepted

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

Submission status: Accepted

Solution code:
class Dice:
    def __init__(self, top, south, east, west, north, bottom):
        self.top = top
        self.south = south
        self.east = east
        self.west = west
        self.north = north
        self.bottom = bottom

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

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

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

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

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

    def printWest(self):
        print(self.west)

    def printEast(self):
        print(self.east)

    def getTop(self, target):
        if self.top == target:
            return
        for i in range(3):
            self.toN()
            if self.top == target:
                return
        for i in range(3):
            self.toE()
            if self.top == target:
                return

        if self.top != target:
            print("Error")

    def getSouth(self, target):
        if self.south == target:
            return
        for i in range(3):
            self.lotate()
            if self.south == target:
                return
    
    def lotate(self):
        tmp = self.north
        self.north = self.east
        self.east = self.south
        self.south = self.west
        self.west = tmp


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

for i in range(count):
    buf = input().split()

    dice.getTop(int(buf[0]))
    dice.getSouth(int(buf[1]))
    dice.printEast()

Submission status: Accepted

Solution code:
class Dice():
    def __init__(self,num):
        self.num = num
    def n_roll(self):
        self.num = [self.num[1],self.num[5],self.num[2],self.num[3],self.num[0],self.num[4]]
    def e_roll(self):
        self.num = [self.num[2],self.num[1],self.num[5],self.num[0],self.num[4],self.num[3]]
    def r_spin(self):
        self.num = [self.num[0],self.num[2],self.num[4],self.num[1],self.num[3],self.num[5]]
dice = Dice(input().split())
n = int(input())
for i in range(n):
    top, front = input().split()
    right = ""
    if top == dice.num[0] or top == dice.num[1] or top == dice.num[4] or top == dice.num[5]:
        for j in range(4):
            if top == dice.num[0]:
                break
            dice.n_roll()
    else:
        for j in range(4):
            dice.e_roll()
            if top == dice.num[0]:
                break
    for j in range(4):
        if top == dice.num[0] and front == dice.num[1]:
            break
        dice.r_spin()
    print(dice.num[2])

Submission status: Accepted

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

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

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

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

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

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

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

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


    def top_fro_right(self, ary): # 回転させて同じダイスになるか
        right = 0
        for _ in range(2):
            for _ in range(3):
                for _ in range(4):
                    if self.is_same_top_fro(ary):
                        right = self.__rit
                    self.spin_r()
                self.turn_n()
            self.spin_r()
            self.turn_s()
        return right

    def is_same_top_fro(self, ary):
        if ary[0] == self.__top and ary[1] == self.__fro:
            return True

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

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

dice = Dice(surfaces)

for _ in range(q):
    top_fro = list(map(int,input().split()))
    right = dice.top_fro_right(top_fro)
    print(right)

Submission status: Accepted

Solution code:
import sys
input = sys.stdin.readline


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

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

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

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

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

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

        return

    def spin(self):
        self.surface = [self.surface[0], self.surface[3], self.surface[1],
                        self.surface[4], self.surface[2], self.surface[5]]
        return

    def get_surface(self, num):
        return self.surface.index(num)

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

    def get_south(self):
        return self.surface[1]

    def get_east(self):
        return self.surface[2]


def main():
    surface = [int(i) for i in input().strip().split()]
    cases = int(input().strip())
    dice = Dice(surface)

    for _ in range(cases):
        top, south = [int(i) for i in input().strip().split()]
        # get current surface
        cur = dice.get_surface(top)
        if cur == 0:
            pass
        elif cur == 1:
            dice.roll("N")
        elif cur == 2:
            dice.roll("W")
        elif cur == 3:
            dice.roll("E")
        elif cur == 4:
            dice.roll("S")
        elif cur == 5:
            dice.roll("S")
            dice.roll("S")
        for _ in range(4):
            dice.spin()
            if dice.get_south() == south:
                print(dice.get_east())


if __name__ == "__main__":
    main()

Submission status: Accepted

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

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

    def roll(self, loc):
        d = {
            'N': (1, 5, 2, 3, 0, 4),
            'S': (4, 0, 2, 3, 5, 1),
            'E': (3, 1, 0, 5, 4, 2),
            'W': (2, 1, 5, 0, 4, 3)
        }
        for i in range(6):
            self.before[i] = self.number[i]

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

    def roll_clockwise(self):
        for i in range(6):
            self.before[i] = self.number[i]
        self.number = [self.before[i] for i in (0, 2, 4, 1, 3, 5)]

    def set_Top_and_Front(self, top, front):
        top_index = self.number.index(top)
        if top_index == 5:
            self.roll('E')
            self.roll('E')
        elif top_index == 4:
            self.roll('S')
        elif top_index == 3:
            self.roll('E')
        elif top_index == 2:
            self.roll('W')
        elif top_index == 1:
            self.roll('N')
        front_index = self.number.index(front)
        if front_index == 1:
            pass
        elif front_index == 2:
            self.roll_clockwise()
        elif front_index == 3:
            self.roll_clockwise()
            self.roll_clockwise()
            self.roll_clockwise()
        elif front_index == 4:
            self.roll_clockwise()
            self.roll_clockwise()

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

    def get_right(self):
        return self.number[2]


if __name__ == '__main__':
    l = list(map(int, input().split()))
    dice = Dice()
    dice.set_number(l)
    m = int(input())
    for _ in range(m):
        i, j = list(map(int, input().split()))
        dice.set_Top_and_Front(i, j)
        print(dice.get_right())

Submission status: Accepted

Solution code:
class dice:
    def __init__(self,A):
        self.side = {
            "TOP":A[0],
            "S":A[1],
            "E":A[2],
            "W":A[3],
            "N":A[4],
            "BOT":A[5],
            }
        self.reverse = {
            "E":"W",
            "W":"E",
            "S":"N",
            "N":"S"}
        
    def main(self,A):
        for s in A:
            var = int(self.side[s])
            self.side[s] = self.side["TOP"]
            self.side["TOP"] = self.side[self.reverse[s]]
            self.side[self.reverse[s]] = self.side["BOT"]
            self.side["BOT"] = var
        # print("{}".format(self.side["TOP"]))
    def rotate(self,top,flont):
        if self.side["TOP"] != top:
            if self.side["BOT"] == top:
                self.main("NN")
            elif self.side["N"] == top:
                self.main("S")
            elif self.side["S"] == top:
                self.main("N")
            elif self.side["E"] == top:
                self.main("W")
            elif self.side["W"] == top:
                self.main("E")
        for x in range(4):
            if self.side["S"] == flont:
                break
            else:
                var = int(self.side["N"])
                self.side["N"] = self.side["E"]
                self.side["E"] = self.side["S"]
                self.side["S"] = self.side["W"]
                self.side["W"] = var
        print(self.side["E"])

var = dice(list(map(int,input().split())))
# var.main(input())
num = int(input())
for n in range(num):
    top,front = map(int,input().split())
    var.rotate(top,front)

Submission status: Accepted

Solution code:
dice_init = input().split()
dicry = {'search':"152304",'hittop':'024135', 'hitfront':'310542'}
num = int(input())

def dicing(x):
    global dice
    dice = [dice[int(c)] for c in dicry[x]]

for _ in range(num):
    dice = dice_init
    top, front = map(int, input().split())
    while True:
        if int(dice[0]) == top and int(dice[1]) == front:
            break
        elif int(dice[0]) == top:
            dicing('hittop')
        elif int(dice[1]) == front:
            dicing('hitfront')
        else:
            dicing('search')
    print(dice[2])

Submission status: Accepted

Solution code:
d = {
    (1,2): 3,
    (1,3): 5,
    (1,4): 2,
    (1,5): 4,
    (2,1): 4,
    (2,3): 1,
    (2,4): 6,
    (2,6): 3,
    (3,1): 2,
    (3,2): 6,
    (3,5): 1,
    (3,6): 5,
    (4,1): 5,
    (4,2): 1,
    (4,5): 6,
    (4,6): 2,
    (5,1): 3,
    (5,3): 6,
    (5,4): 1,
    (5,6): 4,
    (6,2): 4,
    (6,3): 2,
    (6,4): 5,
    (6,5): 3
}

v = list(map(int, input().split()))
q = int(input())
questions = []
for _ in range(q):
    x, y = map(int, input().split())
    questions.append((x,y))

vTod  = dict(zip(v,list(range(1,7))))
dTov  = {v:k for k, v in vTod.items()}

for top, face in questions:
    top = vTod[top]
    face = vTod[face]
    right = d[(top,face)]
    right = dTov[right]
    print(right)

Submission status: Accepted

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

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

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


for i in range(n_question):
    n_top, n_front = map(int, input().split())
    index_n_top = dice.num.index(n_top)
    index_n_front = dice.num.index(n_front)
    
    # print(f"(Init{i}) n_top: {n_top}, n_front: {n_front}")
    # print(f"(Init{i}) dice: {dice.num}")
    # print(f"(Init{i}) index_n_top: {index_n_top}, index_n_front: {index_n_front}")
    # print()
    
    while index_n_top != 0:
        if index_n_top in [0, 1, 4, 5]:
            dice.roll("N")
            index_n_top = dice.num.index(n_top)
            index_n_front = dice.num.index(n_front)
            # print("roll N")
            # print(f"-> index_n_top: {index_n_top}, index_n_front: {index_n_front}")
        else:
            dice.roll("E")
            index_n_top = dice.num.index(n_top)
            index_n_front = dice.num.index(n_front)
            # print("roll E")
            # print(f"-> index_n_top: {index_n_top}, index_n_front: {index_n_front}")
            
    while index_n_front != 1:
            dice.roll("rot_Clock")
            index_n_top = dice.num.index(n_top)
            index_n_front = dice.num.index(n_front)
            # print("roll C")
            # print(f"-> index_n_top: {index_n_top}, index_n_front: {index_n_front}")                
                
    print(dice.num[2])

Submission status: Accepted

Solution code:
from enum import Enum
import sys
import math

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)