- 시뮬레이션 문제
- python deque의 rotate함수 활용
정답코드
import sys
input=sys.stdin.readline
from collections import deque
testcase=int(input())
dir=deque([[-1,0],[0,1],[1,0],[0,-1]])
for _ in range(testcase):
test=input().strip()
max_x,max_y,min_x,min_y=0,0,0,0
x,y=0,0
for c in test:
if c=='L':
dir.rotate(1)
if c=='R':
dir.rotate(-1)
if c=='F':
x=x+dir[0][0]
y=y+dir[0][1]
if c=='B':
x=x-dir[0][0]
y=y-dir[0][1]
max_x=max(x,max_x)
max_y=max(y,max_y)
min_x=min(x,min_x)
min_y=min(y,min_y)
print(abs(max_x-min_x)*abs(max_y-min_y)) #가로*세로
'IT > coding study' 카테고리의 다른 글
[programmers] [3차] 방금그곡 (python) (0) | 2022.01.17 |
---|---|
[programmers] 크레인 인형뽑기 게임 (python) (0) | 2022.01.10 |
[acmicpc] 2252. 줄 세우기(python) (0) | 2021.12.01 |
[acmicpc] 19238. 스타트 택시(python) (0) | 2021.10.24 |
[acmicpc] 21610. 마법사 상어와 비바라기(python) (0) | 2021.10.20 |