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, l):
        self.value = l
    def roll(self,s):
        new_list = [0]*6
        if s == "W":
            new_list[0] = self.value[2]
            new_list[1] = self.value[1]
            new_list[2] = self.value[5]
            new_list[3] = self.value[0]
            new_list[4] = self.value[4]
            new_list[5] = self.value[3]
        if s == "E":
            new_list[0] = self.value[3]
            new_list[1] = self.value[1]
            new_list[2] = self.value[0]
            new_list[3] = self.value[5]
            new_list[4] = self.value[4]
            new_list[5] = self.value[2]
        if s == "N":
            new_list[0] = self.value[1]
            new_list[1] = self.value[5]
            new_list[2] = self.value[2]
            new_list[3] = self.value[3]
            new_list[4] = self.value[0]
            new_list[5] = self.value[4]
        if s == "S":
            new_list[0] = self.value[4]
            new_list[1] = self.value[0]
            new_list[2] = self.value[2]
            new_list[3] = self.value[3]
            new_list[4] = self.value[5]
            new_list[5] = self.value[1]
        self.value = new_list

l = list(map(int,input().split()))
Dice1 = Dice(l)
n = int(input())

for i in range(n):
    one,two = map(int,input().split())
    one_index = Dice1.value.index(one)
    two_index = Dice1.value.index(two)
    if (one_index == 0 and two_index == 1) or (one_index == 1 and two_index == 5) or (one_index == 5 and two_index == 4) or (one_index == 4 and two_index == 0):
        print(Dice1.value[2])
    if (one_index == 1 and two_index == 0) or (one_index == 5 and two_index == 1) or (one_index == 4 and two_index == 5) or (one_index == 0 and two_index == 4):
        print(Dice1.value[3])
    if (one_index == 0 and two_index == 2) or (one_index == 2 and two_index == 5) or (one_index == 5 and two_index == 3) or (one_index == 3 and two_index == 0):
        print(Dice1.value[4])
    if (one_index == 2 and two_index == 0) or (one_index == 5 and two_index == 2) or (one_index == 3 and two_index == 5) or (one_index == 0 and two_index == 3):
        print(Dice1.value[1])
    if (one_index == 1 and two_index == 2) or (one_index == 2 and two_index == 4) or (one_index == 4 and two_index == 3) or (one_index == 3 and two_index == 1):
        print(Dice1.value[0])
    if (one_index == 2 and two_index == 1) or (one_index == 4 and two_index == 2) or (one_index == 3 and two_index == 4) or (one_index == 1 and two_index == 3):
        print(Dice1.value[5])

Submission status: Accepted

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

Submission status: Accepted

Solution code:
class Dice:
    def __init__(self,top,front,right,left,back,bottom):
        self.top, self.bottom=top,bottom
        self.right, self.left=right,left
        self.front, self.back=front,back
    def turn(self,order):
        if order=="N":
            self.top,self.front,self.bottom,self.back=self.front,self.bottom,self.back,self.top
        if order=="S":
            self.top,self.front,self.bottom,self.back=self.back,self.top,self.front,self.bottom
        if order=="E":
            self.top,self.right,self.bottom,self.left=self.left,self.top,self.right,self.bottom
        if order=="W":
            self.top,self.right,self.bottom,self.left=self.right,self.bottom,self.left,self.top

d=map(int,raw_input().split())
dice=Dice(d[0],d[1],d[2],d[3],d[4],d[5])
q=input()
for i in range(q):
    t,f=map(int,raw_input().split())
    if t==d[0]:
        if f==d[1]:
            print d[2]
        elif f==d[2]:
            print d[4]
        elif f==d[4]:
            print d[3]
        elif f==d[3]:
            print d[1]
    elif t==d[1]:
        if f==d[0]:
            print d[3]
        elif f==d[3]:
            print d[5]
        elif f==d[5]:
            print d[2]
        elif f==d[2]:
            print d[0]
    elif t==d[2]:
        if f==d[0]:
            print d[1]
        elif f==d[1]:
            print d[5]
        elif f==d[5]:
            print d[4]
        elif f==d[4]:
            print d[0]
    elif t==d[3]:
        if f==d[0]:
            print d[4]
        elif f==d[4]:
            print d[5]
        elif f==d[5]:
            print d[1]
        elif f==d[1]:
            print d[0]
    elif t==d[4]:
        if f==d[0]:
            print d[2]
        elif f==d[2]:
            print d[5]
        elif f==d[5]:
            print d[3]
        elif f==d[3]:
            print d[0]
    elif t==d[5]:
        if f==d[1]:
            print d[3]
        elif f==d[3]:
            print d[4]
        elif f==d[4]:
            print d[2]
        elif f==d[2]:
            print d[1]
    else:
        print "no answer"

Submission status: Accepted

Solution code:
def move(lon, lat, com):
    target, other, pop_index, insert_index = lon, lat, 0, 3
    if com == "E" or com == "W":
        target, other = lat, lon
    if com == "S" or com == "W":
        pop_index, insert_index = 3, 0
    target.insert(insert_index, target.pop(pop_index))
    other[0], other[2] = target[0], target[2]


def set_upper(lon, lat, upper):
    com = "N" if upper in lon else "E"
    for _i in range(4):
        move(lon, lat, com)
        if lon[0] == upper:
            break


def rotate(lon, lat, com):
    if com == "R":
        lon[1], lat[1], lon[3], lat[3] = lat[3], lon[1], lat[1], lon[3]
    elif com == "L":
        lon[1], lat[1], lon[3], lat[3] = lat[1], lon[3], lat[3], lon[1]


longitude = [1, 2, 6, 5]
latitude = [1, 4, 6, 3]
values = list(input().split())
n = int(input())
for i in range(n):
    U, F = input().split()
    set_upper(longitude, latitude, values.index(U) + 1)
    for j in range(3):
        if longitude[1] == values.index(F) + 1:
            break
        rotate(longitude, latitude, "R")
    print(values[latitude[3] - 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 get_Top(self):
        return self.number[0]
        
    def query(self, top_num, front_num):
        self.save_data = [i for i in range(6)]
        for i in range(6):
            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(6):
            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 sys
import math


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

    def __init__(self):
        self.number = [i for i in range(6)]
        self.work = [i for i in range(6)]
        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:
faces = input().split()

q = int(input())

for i in range(q):
    
    s = input().split()
    
    ss = s[0] + s[1]
    
    if ss in (faces[1] + faces[2] + faces[4] + faces[3] + faces[1]):
        # 1
        print(faces[0])
        
    elif ss in (faces[0] + faces[3] + faces[5] + faces[2] + faces[0]):
        # 2
        print(faces[1])
        
    elif ss in (faces[0] + faces[1] + faces[5] + faces[4] + faces[0]):
        # 3
        print(faces[2])
        
    elif ss in (faces[0] + faces[4] + faces[5] + faces[1] + faces[0]):
        # 4
        print(faces[3])
        
    elif ss in (faces[0] + faces[2] + faces[5] + faces[3] + faces[0]):
        # 5
        print(faces[4])
        
    elif ss in (faces[1] + faces[3] + faces[4] + faces[2] + faces[1]):
        # 6
        print(faces[5])
        
    else:
        print('error', ss)

Submission status: Accepted

Solution code:
def roll_N(self):
    self[0],self[1],self[4],self[5] = self[1],self[5],self[0],self[4]
def roll_W(self):
	self[0],self[2],self[3],self[5] = self[2],self[5],self[0],self[3]
dice = [int(e) for e in input().split()]
times = int(input())
for i in range(times):
    upper,front = map(int,input().split())
    rolleddice = list(dice)
    if front == rolleddice[2] or front == rolleddice[3]:
        roll_W(rolleddice)
    while front != rolleddice[1]:
        roll_N(rolleddice)
    while upper != rolleddice[0]:
        roll_W(rolleddice)
    print(rolleddice[2])

Submission status: Accepted

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

import random

class dice:
    def __init__(self):
        self.top = 0
        self.right = 0
        self.front = 0
        self.left = 0
        self.back = 0
        self.bottom = 0
    
    def set_num(self, nums):
        self.top, self.front, self.right, self.left, self.back, self.bottom = nums
        return self
    
    def get_right(self, f_top, f_front):
        while f_top!=self.top or f_front!=self.front:
            self.roll(random.randint(0,3))
        return self.right
        
    def roll(self, command):
        if command==0:
            self.top, self.front, self.right, self.left, self.back, self.bottom = self.left, self.front, self.top, self.bottom, self.back, self.right
        elif command==1:
            self.top, self.front, self.right, self.left, self.back, self.bottom = self.right, self.front, self.bottom, self.top, self.back, self.left
        elif command==2:
            self.top, self.front, self.right, self.left, self.back, self.bottom = self.front, self.bottom, self.right, self.left, self.top, self.back
        elif command==3:
            self.top, self.front, self.right, self.left, self.back, self.bottom = self.back, self.top, self.right, self.left, self.bottom, self.front
            

d = dice()
d.set_num(nums)

n = int(input())
for i in range(n):
    f_t, f_r = map(int, input().split())
    print(d.get_right(f_t, f_r))

Submission status: Accepted

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

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

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

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

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

init_state = input().split()

for i in range(int(input())):
  dice = Dice(init_state)
  up, front = input().split()

  if up == dice.state[0] \
    and front == dice.state[1]:
      print(dice.state[2])
  else:
    for c in list('NNNNWNNNWNNNENNNENNNWNNN'):       
      if c == 'N':
        dice.north()
      elif c == 'S':
        dice.south()
      elif c == 'W':
        dice.west()
      elif c == 'E':
        dice.east()
      if up == dice.state[0] \
        and front == dice.state[1]:
          print(dice.state[2])
          break

Submission status: Accepted

Solution code:
class dice:
    def __init__(s, i):
        s.d1,s.d2,s.d3,s.d4,s.d5,s.d6 = map(int, i)
        s.dic = {s.d1:{s.d2:s.d3,s.d3:s.d5,s.d4:s.d2,s.d5:s.d4}
                ,s.d2:{s.d1:s.d4,s.d3:s.d1,s.d4:s.d6,s.d6:s.d3}
                ,s.d3:{s.d1:s.d2,s.d2:s.d6,s.d5:s.d1,s.d6:s.d5}
                ,s.d4:{s.d1:s.d5,s.d2:s.d1,s.d5:s.d6,s.d6:s.d2}
                ,s.d5:{s.d1:s.d3,s.d3:s.d6,s.d4:s.d1,s.d6:s.d4}
                ,s.d6:{s.d2:s.d4,s.d3:s.d2,s.d4:s.d5,s.d5:s.d3}}
 
    def get(s, i):
        up, bef = map(int, i)
        return s.dic[up][bef]

dice1 = dice(input().split())
q = int(input())
for i in range(q):
    print(dice1.get(input().split()))

Submission status: Accepted

Solution code:
import random

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

n=list(map(int,input().split()))
m=int(input())
dise=Dise(n[0],n[1],n[2],n[3],n[4],n[5])

for i in range(m):
    a,b=(int(x) for x in input().split())
    for j in range(1000):
        dise.rot(random.choice('NESW'))
        if a==dise.gettop() and b==dise.getfront():
            print(dise.getright())
            break

Submission status: Accepted

Solution code:
class Dice:
    NS = [1, 5, 6, 2]
    EW = [1, 3, 6, 4]

    def question(self, top, front):
        self.setTop(top)
        sides = [self.NS[1], self.EW[1], self.NS[3], self.EW[3]]
        return sides[(sides.index(front) + 3) % 4]

    def setTop(self, n):
        if n in self.NS:
            while self.NS[0] != n:
                self.N()
        else:
            while self.NS[0] != n:
                self.E()

    def N(self):
        tail = self.NS.pop()
        self.NS.insert(0, tail)
        self.EW[0] = self.NS[0]
        self.EW[2] = self.NS[2]

    def E(self):
        tail = self.EW.pop()
        self.EW.insert(0, tail)
        self.NS[0] = self.EW[0]
        self.NS[2] = self.EW[2]


if __name__ == '__main__':
    dnum = input().split()
    for _ in range(int(input())):
        t, f = input().split()
        r = Dice().question(dnum.index(t) + 1, dnum.index(f) + 1)
        print(dnum[r - 1])

Submission status: Accepted

Solution code:

class Dise():
    def __init__(self, aLabelList):
        self.LabelList = aLabelList
        self.LabelsRelationship = [[0 for i in range(5)] for j in range(6)]
        for i in range(6):
            if i == 0:
                self.LabelsRelationship[i][0] = self.LabelList[2 -1] #下1
                self.LabelsRelationship[i][1] = self.LabelList[3 -1] #下2
                self.LabelsRelationship[i][2] = self.LabelList[5 -1] #下3
                self.LabelsRelationship[i][3] = self.LabelList[4 -1] #下4
                self.LabelsRelationship[i][4] = self.LabelList[6 -1] #対面
            elif i == 1:
                self.LabelsRelationship[i][0] = self.LabelList[6 -1] #下1
                self.LabelsRelationship[i][1] = self.LabelList[3 -1] #下2
                self.LabelsRelationship[i][2] = self.LabelList[1 -1] #下3
                self.LabelsRelationship[i][3] = self.LabelList[4 -1] #下4
                self.LabelsRelationship[i][4] = self.LabelList[5 -1] #対面
            elif i == 2:
                self.LabelsRelationship[i][0] = self.LabelList[6 -1] #下1
                self.LabelsRelationship[i][1] = self.LabelList[5 -1] #下2
                self.LabelsRelationship[i][2] = self.LabelList[1 -1] #下3
                self.LabelsRelationship[i][3] = self.LabelList[2 -1] #下4
                self.LabelsRelationship[i][4] = self.LabelList[4 -1] #対面
            elif i == 3:
                self.LabelsRelationship[i][0] = self.LabelList[2 -1] #下1
                self.LabelsRelationship[i][1] = self.LabelList[1 -1] #下2
                self.LabelsRelationship[i][2] = self.LabelList[5 -1] #下3
                self.LabelsRelationship[i][3] = self.LabelList[6 -1] #下4
                self.LabelsRelationship[i][4] = self.LabelList[3 -1] #対面
            elif i == 4:
                self.LabelsRelationship[i][0] = self.LabelList[1 -1] #下1
                self.LabelsRelationship[i][1] = self.LabelList[3 -1] #下2
                self.LabelsRelationship[i][2] = self.LabelList[6 -1] #下3
                self.LabelsRelationship[i][3] = self.LabelList[4 -1] #下4
                self.LabelsRelationship[i][4] = self.LabelList[2 -1] #対面
            elif i == 5:
                self.LabelsRelationship[i][0] = self.LabelList[5 -1] #下1
                self.LabelsRelationship[i][1] = self.LabelList[3 -1] #下2
                self.LabelsRelationship[i][2] = self.LabelList[2 -1] #下3
                self.LabelsRelationship[i][3] = self.LabelList[4 -1] #下4
                self.LabelsRelationship[i][4] = self.LabelList[1 -1] #対面
            
    def DisePrintRight(self,aTopItem,aFront):
        xTopIndex = self.LabelList.index(str(aTopItem))
        for i in range(4):
            if int(self.LabelsRelationship[xTopIndex][i]) == aFront:
                if i + 1 == 4:
                    idxR = int(self.LabelsRelationship[xTopIndex][0])
                else:
                    idxR = int(self.LabelsRelationship[xTopIndex][i+1])
                print(idxR)
                break


myInstance = Dise(input().split())
 
x = int(input())
for i in range(x):
    a,b = map(int, input().split())
    myInstance.DisePrintRight(a,b)

Submission status: Accepted

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

label = list(map(int, input().split() ))
D = Dice(label)
q = int(input())
for qi in range(q):
 t,s = list(map(int, input().split() ))
 t = D.label.index(t)
 s = D.label.index(s)
 n = 5-s
 e = D.East[n][t]
 print(label[e-1])

Submission status: Accepted

Solution code:
#アルゴリズム関数-サイコロを回転させる
def dice_rotation(list1, str1):
    if str1 == "S":
        list1[0],list1[1],list1[4],list1[5] = list1[4],list1[0],list1[5],list1[1]
    elif str1 == "E":
        list1[0],list1[2],list1[3],list1[5] = list1[3],list1[0],list1[5],list1[2]
    elif str1 == "N":
        list1[0],list1[1],list1[4],list1[5] = list1[1],list1[5],list1[0],list1[4]
    elif str1 == "W":
        list1[0],list1[2],list1[3],list1[5] = list1[2],list1[5],list1[0],list1[3]
    return list1

#アルゴリズム関数-上面・前面の番号を指定番号へサイコロを回転させる
def dice_find(list1, int1, int2):
    position_numnber = list1.index(int2)
    if position_numnber == 0:
        list1 = dice_rotation(list1, "S")
    elif position_numnber == 2:
        list1 = dice_rotation(list1, "W")
        list1 = dice_rotation(list1, "S")
    elif position_numnber == 3:
        list1 = dice_rotation(list1, "E")
        list1 = dice_rotation(list1, "S")
    elif position_numnber == 4:
        list1 = dice_rotation(list1, "S")
        list1 = dice_rotation(list1, "S")
    elif position_numnber == 5:
        list1 = dice_rotation(list1, "N")
    position_numnber = list1.index(int1)
    if position_numnber == 2:
        list1 = dice_rotation(list1, "W")
    elif position_numnber == 3:
        list1 = dice_rotation(list1, "E")
    elif position_numnber == 5:
        list1 = dice_rotation(list1, "W")
        list1 = dice_rotation(list1, "W")
    return list1

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

#処理の実行
for count in range(input_count):
    check_number = list(map(int, input().split()))
    input_number = dice_find(input_number, check_number[0], check_number[1])
    result.append(input_number[2])

#結果表示
[print(i) for i in result]

Submission status: Accepted

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

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

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

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

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

    def up_front_to_right(self, top, front):
        if (top, front) in [(self.top, self.front), (self.front, self.bottom), (self.bottom, self.back), (self.back, self.top)]:
            return self.right
        if (top, front) in [(self.front, self.top), (self.bottom, self.front), (self.back, self.bottom), (self.top, self.back)]:
            return self.left
        if (top, front) in [(self.left, self.front), (self.front, self.right), (self.right, self.back), (self.back, self.left)]:
            return self.top
        if (top, front) in [(self.front, self.left), (self.right, self.front), (self.back, self.right), (self.left, self.back)]:
            return self.bottom
        if (top, front) in [(self.top, self.left), (self.left, self.bottom), (self.bottom, self.right), (self.right, self.top)]:
            return self.front
        if (top, front) in [(self.left, self.top), (self.bottom, self.left), (self.right, self.bottom), (self.top, self.right)]:
            return self.back
            
*x,=map(int,input().split())
dice=Dice(x)
q=int(input())
for _ in range(q):
    a,b=map(int,input().split())
    print(dice.up_front_to_right(a,b))

Submission status: Accepted

Solution code:
tbl = [[0,4,2,5,3,0],[3,0,6,1,0,4],[5,1,0,0,6,2],\
       [2,6,0,0,1,5],[4,0,1,6,0,3],[0,3,5,2,4,0]]
num = (input().split())
ite = int(input())
for i in range(ite):
    T,F = map(int,input().split())
    Tin = num.index(str(T))
    Fin = num.index(str(F))
    print(num[tbl[Fin][Tin]-1])

Submission status: Accepted

Solution code:
import math

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

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

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

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

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

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

    def front_and_top_to_right(self,top,front):

        for i in range(4):
            for j in range(4):
                if self.top == top and self.front == front:
                    return self.right
                self.rotate("W")
            self.rotate("S")
        
        self.rotate("NES") #ヨコ回転
        
        for i in range(2):
            for j in range(4):
                if self.top == top and self.front == front:
                    return self.right
                self.rotate("W")
            self.rotate("SS")
        
        return None


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

lst = list(map(int,input().split()))
#lst = [1,2,3,4,5,6]
rep = int(input())
for i in range(rep):
    dice = Dice(lst)
    top,front = list(map(int,input().split()))
    print(dice.front_and_top_to_right(top,front))

Submission status: Accepted

Solution code:
class Dice:
    def __init__(self, dice):
        self.dice = dice
        self.rule={'N':(1,5,2,3,0,4),'S':(4,0,2,3,5,1),'E':(3,1,0,5,4,2),'W':(2,1,5,0,4,3)}
    def output(self):
        return self.dice
    def move(self, direction):
        for _ in direction:
            self.dice = [self.dice[y] for y in self.rule[_]]
        return self.dice

dice = Dice([int(x) for x in input().split()])
for _ in range(int(input())):
    tmp = [int(x) for x in input().split()]
    count = 0
    while dice.output()[0] != tmp[0]:
        if count > 4:
            while dice.output()[0] != tmp[0]: dice.move("E")
            break
        else:
            dice.move("N")
            count += 1

    while dice.output()[1] != tmp[1]: dice.move("ESW")
    print(dice.output()[2])

Submission status: Accepted

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