
https://www.acmicpc.net/problem/3234
문제 전문은 링크 참조
문제가공
- 좌표평면 위에 현재 나의 위치를 입력받는다
- 목표물이 몇 번 움직이는지 입력 받는다.
- 목표물이 움직이는 방향을 입력 받는다.(1초씩움직임)
- 나의 위치에 근접해오는 시간대를 출력한다.(없으면 -1)
코드작성
방향 정보 : ('I': 오른쪽, 'S': 위쪽, 'Z': 왼쪽, 'J': 아래쪽)
me =list( map(int,input().split()))
sec = int(input())
d = input()
target = [0,0]
direction = {'I':[1,0],'S':[0,1],'Z':[-1,0],'J':[0,-1]}
arr=[]
i =0
if abs(me[0]-target[0])<=1 and abs(me[1]-target[1])<=1:
arr.append(i)
for c in d:
i+=1
target[0]+=direction[c][0]
target[1]+=direction[c][1]
if abs(me[0]-target[0])<=1 and abs(me[1]-target[1])<=1:
arr.append(i)
print(*arr if len(arr)>0 else '-1',sep='\\n')
'Python > 백준 (BOJ)' 카테고리의 다른 글
| [BOJ][B2]Adding Reversed Numbers - 3486 (0) | 2025.09.28 |
|---|---|
| [BOJ][B2]Vigenère Cipher Encryption - 3417 (0) | 2025.09.27 |
| [BOJ][B2]dates - 3183 (0) | 2025.09.25 |
| [BOJ][B2]줄임말 만들기 - 3181 (0) | 2025.09.24 |
| [BOJ][B2]상근이의 체스판 - 3076 (0) | 2025.09.23 |