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:
s = list(map(int,input().split()))
q = int(input())

while q > 0:
  top, front = map(int,input().split())
  
  if s.index(top) == 1:
    ORDER = 'N'
  elif s.index(top) == 2:
    ORDER = 'W'
  elif s.index(top) == 3:
    ORDER = 'E'
  elif s.index(top) == 4:
    ORDER = 'S'
  elif s.index(top) == 5:
    ORDER = 'SS'
  else:
    ORDER = 'R'
  
  order = list(ORDER)
  
  for i in order:
    if i == 'E':
      s[0], s[3] = s[3], s[0]
      s[3], s[5] = s[5], s[3]
      s[5], s[2] = s[2], s[5]
    elif i == 'N':
      s[0], s[1] = s[1], s[0]
      s[1], s[5] = s[5], s[1]
      s[5], s[4] = s[4], s[5]
    elif i == 'S':
      s[0], s[4] = s[4], s[0]
      s[4], s[5] = s[5], s[4]
      s[5], s[1] = s[1], s[5] 
    elif i == 'W':
      s[0], s[2] = s[2], s[0]
      s[2], s[5] = s[5], s[2]
      s[5], s[3] = s[3], s[5]
    else:
      pass
    
  if s.index(front) == 1:
    print(s[2])
  if s.index(front) == 2:  
    print(s[4])
  if s.index(front) == 3:  
    print(s[1])
  if s.index(front) == 4:
    print(s[3])
    
  q = q-1

Submission status: Accepted

Solution code:
a,b,c,d,e,f = map(int,input().split())

num = int(input())

def dice1(x):
  if x == b:
    return c
  elif x == c:
    return e
  elif x == d:
    return b
  else:
    return d
  
def dice2(x):
  if x == a:
    return d
  elif x == c:
    return a
  elif x == d:
    return f
  else:
    return c
  
def dice3(x):
  if x == a:
    return b
  elif x == b:
    return f
  elif x == e:
    return a
  else:
    return e

def dice4(x):
  if x == a:
    return e
  elif x == b:
    return a
  elif x == e:
    return f
  else:
    return b

def dice5(x):
  if x == a:
    return c
  elif x == c:
    return f
  elif x == d:
    return a
  else:
    return d
  
def dice6(x):
  if x == b:
    return d
  elif x == c:
    return b
  elif x == d:
    return e
  else:
    return c
  
for i in range(num):
  j,k=map(int,input().split())
  if j == a:
    print(dice1(k))
  elif j == b:
    print(dice2(k))
  elif j == c:
    print(dice3(k))
  elif j == d:
    print(dice4(k))
  elif j == e:
    print(dice5(k))
  else:
    print(dice6(k))

Submission status: Accepted

Solution code:
class Dice:
    # 0: top, 1: front, 2: right, 3: left, 4: back, 5: bottom
    def __init__(self, n0, n1, n2, n3, n4, n5):
        self.faces = [n0, n1, n2, n3, n4, n5]

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

    def spin_horizontally(self):
        tmp = self.faces[1]
        self.faces[1] = self.faces[2]
        self.faces[2] = self.faces[4]
        self.faces[4] = self.faces[3]
        self.faces[3] = tmp

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

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

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

n = list(map(int, input().split()))
dice = Dice(n[0], n[1], n[2], n[3], n[4], n[5])
q = int(input())
for _ in range(q):
    t, f = map(int, input().split())

    for i in range(5):
        if dice.top() == t:
            break
        if i % 2 == 0:
            dice.move('S')
        else:
            dice.move('E')

    for i in range(3):
        if dice.front() == f:
            break
        dice.spin_horizontally()

    print(dice.right())

Submission status: Accepted

Solution code:
#这个也是在模拟，不过是吧骰子反转到正面和侧面一样 (⊙o⊙)？，不知道有没有简单的方法
start = [0,1,2,4,3,5]#上 正 右 后 左 下
s = []
#下面的是几个反转方式
def N():
    start[0],start[1],start[3],start[5] = \
    start[1],start[5],start[0],start[3]
    
def S():
    start[0],start[1],start[3],start[5] = \
    start[3],start[0],start[5],start[1]
    
def W():
    start[0],start[2],start[4],start[5] = \
    start[2],start[5],start[0],start[4]

def E():
    start[0],start[2],start[4],start[5] = \
    start[4],start[0],start[5],start[2]    


#这是特殊的旋转方法
def roll():
    start[1],start[2],start[3],start[4] = \
    start[4],start[1],start[2],start[3]          

def get_top():
    return s[start[0]]

def get_zhengMian():
    return s[start[1]]

def get_right():
    return s[start[2]]

def get_left():
    return s[start[4]]

if __name__=='__main__':
    s = list(map(int,input().split()))
    num = int(input())
    for i in range(num):
        a,b = map(int,input().split())
        if a!=get_top():
            right =get_right()
            left = get_left()
            top = get_top()
            if(a==right):
                W()
            elif a==left:
                E()
            while a!=top:
                S()
                top = get_top()
        zhengmian = get_zhengMian()
        right = get_right()
        if b!=zhengmian:
            while b!=zhengmian:
                roll()
                zhengmian = get_zhengMian()
        print(get_right())

Submission status: Accepted

Solution code:
d = list(map(int, input().split()))
q = int(input())
for i in range(q):
    right = 0
    top, front = map(int, input().split())

    if top == d[0]:
        if front == d[1]:
            print(d[2])
        elif front == d[2]:
            print(d[4])
        elif front == d[3]:
            print(d[1])
        elif front == d[4]:
            print(d[3])
    elif top == d[1]:
        if front == d[0]:
            print(d[3])
        elif front == d[2]:
            print(d[0])
        elif front == d[3]:
            print(d[5])
        elif front == d[5]:
            print(d[2])
    elif top == d[2]:
        if front == d[0]:
            print(d[1])
        elif front == d[1]:
            print(d[5])
        elif front == d[4]:
            print(d[0])
        elif front == d[5]:
            print(d[4])
    elif top == d[3]:
        if front == d[0]:
            print(d[4])
        elif front == d[1]:
            print(d[0])
        elif front == d[4]:
            print(d[5])
        elif front == d[5]:
            print(d[1])
    elif top == d[4]:
        if front == d[0]:
            print(d[2])
        elif front == d[2]:
            print(d[5])
        elif front == d[3]:
            print(d[0])
        elif front == d[5]:
            print(d[3])
    elif top == d[5]:
        if front == d[1]:
            print(d[3])
        elif front == d[2]:
            print(d[1])
        elif front == d[3]:
            print(d[4])
        elif front == d[4]:
            print(d[2])
    else:
        break

Submission status: Accepted

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

# dai[0] 上 
# dai[1] 前 
# dai[2] 右
# dai[3] 左
# dai[4] 後
# dai[5] 下

def zenten():
	dai0 = dai[0]
	dai[0] = dai[4]
	dai[4] = dai[5]
	dai[5] = dai[1]
	dai[1] = dai0

def tokei():
	dai1 = dai[1]
	dai[1] = dai[2]
	dai[2] = dai[4]
	dai[4] = dai[3]
	dai[3] = dai1
	
n=int(input())

def check():
	for j in range(4):
		if a == dai[0] and b == dai[1]:
			print(dai[2])
			return True
		tokei()
	return False

for m in range(n):
	a,b=map(int,input().split())
	# a 上の番号
	# b 前の番号
	if not check():# 0
		zenten()
		if not check(): # 4
			zenten()
			if not check(): # 5
				zenten()
				if not check(): # 1
					tokei()
					zenten()
					if not check(): # 3
						zenten()
						zenten()
						if not check(): #2
							print("ERROR")

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:
import random

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

    def __init__(self):
        self.number = [i for i in range(6)]  #[0, 1, 2, 3, 4, 5]
        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 roll_2(self, top, front):  # 上面と前面の整数から右側の面の整数を求めるメソッド
        directions = ["N", "E", "W", "S"]
        while True:
            i = random.randint(0, 3)
            self.roll(directions[i])
            if top == self.number[0] and front == self.number[1]:
                break
        return self.number[2]

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

num = list(map(int, input().split()))
dice = Dice()
dice.setNumber(num[0], num[1], num[2], num[3], num[4], num[5])
q = int(input())  # 質問の数
for i in range(q):
    top, front = map(int, input().split())
    print(dice.roll_2(top, front))

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)

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)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
def move(dice, order):
  if order == "E":
    temp = dice[0]
    dice[0] = dice[3]
    dice[3] = dice[5]
    dice[5] = dice[2]
    dice[2] = temp
  elif order == "N":
    temp = dice[0]
    dice[0] = dice[1]
    dice[1] = dice[5]
    dice[5] = dice[4]
    dice[4] = temp
  elif order == "S":
    temp = dice[0]
    dice[0] = dice[4]
    dice[4] = dice[5]
    dice[5] = dice[1]
    dice[1] = temp
  elif order == "W":
    temp = dice[0]
    dice[0] = dice[2]
    dice[2] = dice[5]
    dice[5] = dice[3]
    dice[3] = temp
  else:
    pass
  return dice
 
def roll(dice):
  temp = dice[1]
  dice[1] = dice[2]
  dice[2] = dice[4]
  dice[4] = dice[3]
  dice[3] = temp
  return dice
 
dice = list(map(int, input().split()))
q = int(input())
for i in range(q):
  up, front = map(int, input().split())
  cnt = 0
  while (dice[0] != up and cnt <= 3):
    dice = move(dice, "E")
    cnt += 1
  while dice[0] != up:
    dice = move(dice, "N")
  while dice[1] != front:
    dice = roll(dice)
  print(dice[2])

Submission status: Accepted

Solution code:
def initialize(faces_int: list) -> list:
    list_sn = [faces_int[5], faces_int[4], faces_int[0], faces_int[1]]  # 6,5,1,2
    list_we = [faces_int[5], faces_int[2], faces_int[0], faces_int[3]]  # 6,3,1,4
    return [list_sn, list_we]


def roll_positive(list_a: list, list_b: list) -> list:
    list_a = list_a[1:] + list_a[0:1]  # Roll one unit in the positive direction.
    list_b[0] = list_a[0]  # Change the bottom face.
    list_b[2] = list_a[2]  # Change the top face.
    return [list_a, list_b]


def roll_negative(list_a: list, list_b: list) -> list:
    list_a = list_a[3:] + list_a[0:3]
    list_b[0] = list_a[0]  # Change the bottom face.
    list_b[2] = list_a[2]  # Change the top face.
    return [list_a, list_b]


if __name__ == "__main__":
    faces_int = list(map(lambda x: int(x), input().split()))  # 1,2,3,4,5,6
    question_num = int(input())

    for _ in range(question_num):
        SN_direction, WE_direction = initialize(faces_int)
        q_top, q_front = map(lambda x: int(x), input().split())
        for command in "NNNNWNNNWNNNENNNENNNWNNN":  # Check all patterns.
            if ("N" == command):
                SN_direction, WE_direction = roll_positive(SN_direction, WE_direction)
            elif ("S" == command):
                SN_direction, WE_direction = roll_negative(SN_direction, WE_direction)
            elif ("E" == command):
                WE_direction, SN_direction = roll_positive(WE_direction, SN_direction)
            else:
                WE_direction, SN_direction = roll_negative(WE_direction, SN_direction)
            if SN_direction[2] == q_top and SN_direction[3] == q_front:
                print(f"{WE_direction[1]}")  # Print the right side face.
                break

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)]
        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:
n = list(map(int, input().split()))
#print(n)
qn = int(input())
question = []
for i in range(qn):
    q = list(map(int, input().split()))
    question.append(q)

right = []
for i in range(qn):
    x = n
    if question[i][0] == x[1]:  #N(北)に回転
        temp = x[0]
        x[0] = x[1]
        x[1] = x[5]
        x[5] = x[4]
        x[4] = temp
    elif question[i][0] == x[2]:  #W(西)に回転
        temp = x[0]
        x[0] = x[2]
        x[2] = x[5]
        x[5] = x[3]
        x[3] = temp
    elif question[i][0] == x[3]:  #E(東)に回転
        temp = x[0]
        x[0] = x[3]
        x[3] = x[5]
        x[5] = x[2]
        x[2] = temp
    elif question[i][0] == x[4]:  #S(南)に回転
        temp = x[0]
        x[0] = x[4]
        x[4] = x[5]
        x[5] = x[1]
        x[1] = temp
    elif question[i][0] == x[5]:  #S(南)に２回転
        for k in range(2):
            temp = x[0]
            x[0] = x[4]
            x[4] = x[5]
            x[5] = x[1]
            x[1] = temp

    if question[i][1] != x[1]:
        if question[i][1] == x[2]:  #地面から垂直に左回転
            temp = x[2]
            x[2] = x[4]
            x[4] = x[3]
            x[3] = x[1]
            x[1] = temp
        elif question[i][1] == x[3]:  #地面から垂直の右回転
            temp = x[3]
            x[3] = x[4]
            x[4] = x[2]
            x[2] = x[1]
            x[1] = temp
        elif question[i][1] == x[4]:  #地面から垂直に２回右回転
            for k in range(2):
                temp = x[3]
                x[3] = x[4]
                x[4] = x[2]
                x[2] = x[1]
                x[1] = temp
    right.append(x[2])

for i in right:
    print(i)

Submission status: Accepted

Solution code:
import copy
class Dice:
    def __init__(self, a, b, c, d, e, f):
        self.top = a
        self.front = b
        self.right = c
        self.left = d
        self.behind = e
        self.bottom = f

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

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

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

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


dice=Dice(*[int(i) for i in input().split(" ")])

n=int(input())
for i in range(n):
    top,front=[int(j) for j in input().split(" ")]
    while(dice.front!=front):
        if(dice.left==front or dice.right==front):
            dice.E()
        else:
            dice.N()
    while(dice.top!=top):
        dice.E()
    print(dice.right)

Submission status: Accepted

Solution code:
class dice():
    
    def __init__(self,a,b,c,d,e,f):
        self.A=[a,b,c,d,e,f]
        self.temp=[]
        
    def q_method(self,x,y):
       for i in self.A:
        self.temp.append(i)       

        #xとyが何番目の配列かを確認する
        n=self.A.index(x)
        m=self.A.index(y)

       if n==0:
           if m==1:
               print(self.A[2])
           elif m==2:
               print(self.A[4])
           elif m==3:
               print(self.A[1])
           elif m==4:
               print(self.A[3])
       elif n==1:
           if m==0:
              print(self.A[3])
           elif m==2:
              print(self.A[0])
           elif m==3:
              print(self.A[5])
           elif m==5:
               print(self.A[2])
       elif n==2:
           if m==0:
               print(self.A[1])
           elif m==1:
               print(self.A[5])
           elif m==4:
               print(self.A[0])
           elif m==5:
               print(self.A[4])
       elif n==3:
           if m==0:
               print(self.A[4])
           elif m==1:
               print(self.A[0])
           elif m==4:
               print(self.A[5])
           elif m==5:
               print(self.A[1])

       elif n==4:
           if m==0:
               print(self.A[2])
           elif m==2:
               print(self.A[5])
           elif m==3:
               print(self.A[0])
           elif m==5:
               print(self.A[3])
       elif n==5:
           if m==1:
               print(self.A[3])
           elif m==2:
               print(self.A[1])
           elif m==3:
               print(self.A[4])
           elif m==4:
               print(self.A[2])

       
       
if __name__=="__main__":

    input_text=""
    input_text=input()
    array=[]
    array=input_text.split()

    ob1=dice(array[0],array[1],array[2],array[3],array[4],array[5])

    question=input()
    question=int(question)

    for i in range(question):
        input_order=input()

        order_array=[]
        order_array=input_order.split()
        ob1.q_method(order_array[0],order_array[1])

Submission status: Accepted

Solution code:
def dice_move(a1,a2,a3,a4,a5,a6,s):
    for i in s:
        if i=="E":
            a1,a2,a3,a4,a5,a6=a4,a2,a1,a6,a5,a3
        elif i=="S":
            a1,a2,a3,a4,a5,a6=a5,a1,a3,a4,a6,a2
        elif i=="W":
            a1,a2,a3,a4,a5,a6=a3,a2,a6,a1,a5,a4
        elif i=="N":
            a1,a2,a3,a4,a5,a6=a2,a6,a3,a4,a1,a5
    return None

def dice_place(top,front,a1,a2,a3,a4,a5,a6):
    if top==a1:
        ans=[0,0,a3,a5,a2,a4,0]
    elif top==a2:
        ans=[0,a4,0,a1,a6,0,a3]
    elif top==a3:
        ans=[0,a2,a6,0,0,a1,a5]
    elif top==a4:
        ans=[0,a5,a1,0,0,a6,a2]
    elif top==a5:
        ans=[0,a3,0,a6,a1,0,a4]
    elif top==a6:
        ans=[0,0,a4,a2,a5,a3,0]
    front%=10
    return ans[front]
    
a1,a2,a3,a4,a5,a6=map(int,input().split())
n=int(input())
for i in range(n):
    t,f=map(int,input().split())
    print(dice_place(t,f,a1,a2,a3,a4,a5,a6))

Submission status: Accepted

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

	def dice_n(self):
		self.d[4],self.d[0],self.d[1],self.d[5] = self.d[0],self.d[1],self.d[5],self.d[4]
		if (([self.d[0],self.d[1]],self.d[2])) not in self.rp:
			self.rp.append(([self.d[0],self.d[1]],self.d[2]))

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

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

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

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

	def check_dice(self,n,m):
		for i in range(len(self.rp)):
			if self.rp[i][0] == [n,m]:
				return self.rp[i][1]

	def print_dice(self):
		print(self.rp)

if __name__ == '__main__':

	dd = list(map(int,input().split()))
	num = int(input())
	line = "NNNNWNNNNWNNNNWNNNNNENNNNENNNNENNNN"

	d = Dice()

	for di in line:
		if di == "N":
			d.dice_n()
		elif di == "S":
			d.dice_s()
		elif di == "W":
			d.dice_w()
		elif di == "E":
			d.dice_e()

	for i in range(num):
		n,m = map(int,input().split())
		nn = dd.index(n)
		mm = dd.index(m)
		ret = d.check_dice(nn,mm)
		print(dd[ret])

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-
# ITP1_11_B

class Dice:
    def __init__(self, num):
        self.num = num
        
    def show_r(self):
        """ 出目を表示する """
        print(self.num[2])
        
    def roll(self, direction):
        """ 転がす処理 """
        data = []
        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]
        elif direction == "L":
            data = [0, 2, 4, 1, 3, 5]
        elif direction == "R":
            data = [0, 3, 1, 4, 2, 5]

        for i in data:
            new_num.append(self.num[i])
        self.num = new_num
        
def dice_roll1(dice, dice_tf):
    dice_roll = ""
    top = dice_tf[0]
    
    if dice.num.index(top) == 1:
        dice_roll = "N"
    elif dice.num.index(top) == 2:
        dice_roll = "W"
    elif dice.num.index(top) == 3:
        dice_roll = "E"
    elif dice.num.index(top) == 4:
        dice_roll = "S"
    elif dice.num.index(top) == 5:
        dice_roll = "NN"
        
    return dice_roll

def dice_roll2(dice, dice_tf):
    dice_roll = ""
    front = dice_tf[1]
    
    if dice.num.index(front) == 2:
        dice_roll = "L"
    elif dice.num.index(front) == 3:
        dice_roll = "R"
    elif dice.num.index(front) == 4:
        dice_roll = "LL"
        
    return dice_roll

dice1 = Dice(list(map(int, input().split())))

dice_tf = []
for i in range(int(input())):
    dice_tf.append(list(map(int, input().split())))

for i in dice_tf:
    direction = dice_roll1(dice1, i)
    for j in direction:
        dice1.roll(j)
    
    direction = dice_roll2(dice1, i)
    for j in direction:
        dice1.roll(j)
        
    dice1.show_r()

Submission status: Accepted

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

for i in range(n):
  q=list(map(int,input().split()))
  if q in [[S[3],S[1]],[S[1],S[2]],[S[2],S[4]],[S[4],S[3]]]:
           print(S[0])
           
  if q in [[S[0],S[3]],[S[3],S[5]],[S[5],S[2]],[S[2],S[0]]]:
           print(S[1])
           
  if q in [[S[0],S[1]],[S[1],S[5]],[S[5],S[4]],[S[4],S[0]]]:
           print(S[2])
           
  if q in [[S[4],S[5]],[S[5],S[1]],[S[1],S[0]],[S[0],S[4]]]:
           print(S[3])
           
  if q in [[S[0],S[2]],[S[2],S[5]],[S[5],S[3]],[S[3],S[0]]]:
           print(S[4])
  
  if q in [[S[2],S[1]],[S[1],S[3]],[S[3],S[4]],[S[4],S[2]]]:
           print(S[5])

Submission status: Accepted

Solution code:
table = [[0, 3, 5 ,2, 4, 0],
         [4, 0, 1, 6, 0, 3],
         [2, 6, 0, 0, 1, 5],
         [5, 1, 0, 0, 6, 2],
         [3, 0, 6, 1, 0, 4],
         [0, 4, 2, 5, 3, 0]]

l = list(map(int, input().split()))
for i in range(int(input())):
    u, f = map(int, input().split())
    print(l[table[l.index(u)][l.index(f)] - 1])

Submission status: Accepted

Solution code:
class Dice:
    def __init__(self, num_list):
        self.faces= num_list
        
    def find_rf(self,top,front):
        tf = str(self.faces.index(top)) + str(self.faces.index(front))
        if tf in '12431':
            return self.faces[0]
        elif tf in '03520':
            return self.faces[1]
        elif tf in '01540':
            return self.faces[2]
        elif tf in '04510':
            return self.faces[3]
        elif tf in '02530':
            return self.faces[4]
        else:
            return self.faces[5]


dice = Dice(tuple(map(int,input().split())))
q = int(input())

for i in range(q):
    top, front = map(int, input().split())
    right_face = dice.find_rf(top,front)
    print(right_face)