IT/coding study

[acmicpc] 8911. 거북이(python)

seyeonHello 2021. 12. 27. 22:40
  • 시뮬레이션 문제
  • 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