문제
https://www.acmicpc.net/problem/14499
코드
import sys
input=sys.stdin.readline
def turn(dir):
a, b, c, d, e, f = dice[0], dice[1], dice[2], dice[3], dice[4], dice[5]
if dir == 1: #동
dice[0], dice[1], dice[2], dice[3], dice[4], dice[5] = d, b, a, f, e, c
elif dir == 2: #서
dice[0], dice[1], dice[2], dice[3], dice[4], dice[5] = c, b, f, a, e, d
elif dir == 3: #북
dice[0], dice[1], dice[2], dice[3], dice[4], dice[5] = e, a, c, d, f, b
else: #남
dice[0], dice[1], dice[2], dice[3], dice[4], dice[5] = b, f, c, d, a, e
dx=[0,0,0,-1,1]
dy=[0,1,-1,0,0]
n,m,x,y,k=map(int, input().split())
array=[list(map(int, input().split())) for _ in range(n)]
direction=list(map(int, input().split()))
dice = [0] * 6
for dir in direction:
if 0<=x+dx[dir]<n and 0<=y+dy[dir]<m:
x+=dx[dir]
y+=dy[dir]
turn(dir)
if array[x][y]==0:
array[x][y]=dice[-1]
else:
dice[-1]=array[x][y]
array[x][y]=0
print(dice[0])
생각 정리
주사위를 돌릴때, 인덱스의 변화를 생각하기 까다로웠다.
'문제풀이 > 구현' 카테고리의 다른 글
● [파이썬] [구현] 백준 15685 드래곤 커브 (0) | 2023.03.28 |
---|---|
○ [파이썬] [구현] 백준 15683 감시 (0) | 2023.03.27 |
● [파이썬] [구현] 백준 21610 마법사 상어와 비바라기 (0) | 2023.03.22 |
@ [파이썬] [구현] 백준 21608 상어 초등학교 (0) | 2023.03.20 |
● [파이썬] [구현] 백준 14891 톱니바퀴 (0) | 2023.03.18 |