-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path1.py
More file actions
46 lines (40 loc) ยท 942 Bytes
/
1.py
File metadata and controls
46 lines (40 loc) ยท 942 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
# ๋์ ํ์ด
n = int(input())
cmd = input().split()
x, y = 1, 1
for i in cmd:
tempX, tempY = x, y
if i == 'L':
tempY -= 1
elif i == 'R':
tempY += 1
elif i == 'U':
tempX -= 1
elif i == 'D':
tempX += 1
if(tempX < 1 or tempY < 1 or tempX > n or tempY > n):
continue
x, y = tempX, tempY
print(x, y)
# ๋๋๋น๋ ํ์ด
# N ์
๋ ฅ๋ฐ๊ธฐ
n = int(input())
x, y = 1, 1
plans = input().split()
# L, R, U, D์ ๋ฐ๋ฅธ ์ด๋ ๋ฐฉํฅ
dx = [0, 0, -1, 1]
dy = [-1, 1, 0, 0]
move_types = ['L', 'R', 'U', 'D']
# ์ด๋ ๊ณํ์ ํ๋์ฉ ํ์ธ
for plan in plans:
# ์ด๋ ํ ์ขํ ๊ตฌํ๊ธฐ
for i in range(len(move_types)):
if plan == move_types[i]:
nx = x + dx[i]
ny = y + dy[i]
# ๊ณต๊ฐ์ ๋ฒ์ด๋๋ ๊ฒฝ์ฐ ๋ฌด์
if nx < 1 or ny < 1 or nx > n or ny > n:
continue
# ์ด๋ ์ํ
x, y = nx, ny
print(x, y)