[READ-ONLY] Mirror of https://github.com/shuuji3/competitive-programming. 馃洬 Codes submitted to competitive programming platforms
aizu-online-jadge aoj atcoder hackerrank leetcode
0

Configure Feed

Select the types of activity you want to include in your feed.

1class Dice: 2 def __init__(self, top: str, front: str, right: str, left: str, back: str, bottom: str) -> None: 3 self.top = top 4 self.front = front 5 self.right = right 6 self.left = left 7 self.back = back 8 self.bottom = bottom 9 10 def print_top(self): 11 print(self.top) 12 13 def print_right(self): 14 print(self.right) 15 16 def roll(self, direction: str) -> None: 17 if direction == 'S': 18 self.south() 19 elif direction == 'N': 20 self.north() 21 elif direction == 'E': 22 self.east() 23 elif direction == 'W': 24 self.west() 25 26 def north(self): 27 [self.top, self.back, self.bottom, self.front] = [self.front, self.top, self.back, self.bottom] 28 29 def south(self): 30 [self.top, self.back, self.bottom, self.front] = [self.back, self.bottom, self.front, self.top] 31 32 def east(self): 33 [self.top, self.right, self.bottom, self.left] = [self.left, self.top, self.right, self.bottom] 34 35 def west(self): 36 [self.top, self.right, self.bottom, self.left] = [self.right, self.bottom, self.left, self.top] 37 38 def rotate_right(self) -> None: 39 for direction in 'SWN': 40 self.roll(direction) 41 42 43def solve(dice: Dice, top: str, front: str) -> None: 44 # find top 45 found = False 46 for direction in 'SSSS': 47 dice.roll(direction) 48 if dice.top == top: 49 found = True 50 break 51 if not found: 52 for direction in 'EEE': 53 dice.roll(direction) 54 if dice.top == top: 55 break 56 57 # find front 58 for _ in range(4): 59 dice.rotate_right() 60 if dice.front == front: 61 break 62 63 # answer right 64 dice.print_right() 65 66 67labels = input().split() 68dice = Dice(*labels) 69n = int(input()) 70for i in range(n): 71 top, front = input().split() 72 solve(dice, top, front)