- 시뮬레이션 문제
- 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)) #가로*세로
https://www.acmicpc.net/problem/8911
8911번: 거북이
첫째 줄에 테스트 케이스의 개수 T가 주어진다. 각 테스트 케이스는 한 줄로 이루어져 있고, 컨트롤 프로그램이 주어진다. 프로그램은 항상 문제의 설명에 나와있는 네가지 명령으로만 이루어져
www.acmicpc.net
'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 |