FeelingXD

[๋ฐฑ์ค€-1063] ํ‚น โ™Ÿ๏ธ ๋ณธ๋ฌธ

์นดํ…Œ๊ณ ๋ฆฌ ์—†์Œ

[๋ฐฑ์ค€-1063] ํ‚น โ™Ÿ๏ธ

FeelingXD 2024. 1. 6. 22:08

โ“ Problem

๐Ÿค” How

๊ตฌํ˜„, ์‹œ๋ฎฌ๋ ˆ์ด์…˜ ๋ฌธ์ œ์ด๋‹ค ์ฒด์ŠคํŒ์—์„œ ํ‚น์˜ ์›€์ง์ž„์„ ์ƒ๊ฐ ํ•ด๋ณด์ž.

์›€์ง์ž„ ์กฐ๊ฑด์— ๋”ฐ๋ผ ๊ณ ๋ ค ํ•ด์•ผ ํ•  ๊ฒƒ

  1. ํ‚น์€ ์ƒํ•˜์ขŒ์šฐ ๋Œ€๊ฐ ๋ชจ๋“ ๋ฐฉํ–ฅ์„ 1์นธ์›€์ง์ผ ์ˆ˜ ์žˆ์œผ๋ฉฐ ์ด๋™ํ•  ์œ„์น˜์— ํฐ์ด ์žˆ์„๊ฒฝ์šฐ ๊ฐ™์€ ๋ฐฉํ–ฅ์œผ๋กœ ๋ฐ€๋ฉด์„œ ์ด๋™ํ•ด์•ผํ•œ๋‹ค.
  2. ํ‚น์ด ์›€์ง์ผ์ˆ˜ ์—†๋Š” ์ž…๋ ฅ์ด ๋‚˜์˜ฌ๊ฒฝ์šฐ ํ•ด๋‹น ๋ช…๋ น์€ ๊ฑด๋„ˆ๋›ด๋‹ค.
  3. ํ‚น์ด ํฐ์„ ๋ฐ€๋ฉด์„œ ์›€์ง์ผ๋•Œ ๋ฐ€๋ฆฐ ํฐ์ด ์ด๋™ํ• ์ˆ˜์—†๋Š”๊ฒฝ์šฐ(๋ณด๋“œ ๋ฐ–์œผ๋กœ ๋‚˜๊ฐ€๋ฒ„๋ฆฌ๋Š” ๊ฒฝ์šฐ) ์ด๊ฒฝ์šฐ ๋˜ํ•œ ํ‚น์ด ์ด๋™ํ• ์ˆ˜์—†๋‹ค.

์ž…๋ ฅ ์กฐ๊ฑด์— ๋”ฐ๋ผ ๊ณ ๋ ค ํ•ด์•ผ ํ•  ๊ฒƒ

์ž…๋ ฅ์ด ์ฒด์Šค ์œ„์น˜ํ‘œ์‹œ๋กœ ์ •ํ•ด์ง„๋‹ค. ์ขŒํ‘œ๊ฐ’ ์œผ๋กœ ์ฃผ์–ด์ง€๋Š”๊ฒƒ์ด์•„๋‹ˆ๋ฏ€๋กœ ์ ์ ˆํ•˜๊ฒŒ ๋ณ€ํ™˜ํ•ด ์ฃผ์–ด์•ผ ํ•œ๋‹ค. ํ•„์ž๋Š” ํ–‰์„ y๋กœ ์—ด์„ x๋กœ ๋‘๊ณ .
์ž…๋ ฅ์—๋”ฐ๋ผ ์ ์ ˆํžˆ ๋ณ€ํ™” ํ•˜๋Š” ์ฝ”๋“œ๋ฅผ ์ž‘์„ฑํ–ˆ๋‹ค.

โ— Solve

# ํ‚น
import sys
input =sys.stdin.readline
move={"R":(0,1),"L":(0,-1),"T":(-1,0),"B":(1,0),"RT":(-1,1),"LT":(-1,-1),"RB":(1,1),"LB":(1,-1)}
'''
y= ์ˆซ์ž ์ขŒํ‘œ
x= ๋ฌธ์ž ์ขŒํ‘œ
'''
def board_to_pos(word): # ์ฒด์Šค๋ณด๋“œ ์œ„์น˜๋ฅผ ์ขŒํ‘œ๋กœ ๋ณ€ํ™˜
    x=ord(word[0])-ord('A')
    y=8-int(word[1])
    return (y,x)

def pos_to_board(pos): # ์ขŒํ‘œ๋ฅผ ์ฒด์Šค๋ณด๋“œ ์œ„์น˜๋กœ ๋ณ€ํ™˜
    y,x=pos
    return chr(x+ord('A'))+str(8-y)

def unit_move(next_move):
    global k_pos, p_pos

    k_cy,k_cx=k_pos
    dy,dx=move[next_move]

    k_ny,k_nx=k_cy+dy,k_cx+dx
    if not (0<=k_ny<8 and 0<=k_nx<8): # ์™•์ด ๋ณด๋“œ์นธ์„ ๋„˜์–ด๊ฐ€๋Š” ๊ฒฝ์šฐ
        return
    elif (k_ny,k_nx)==p_pos: # ์™•์ด ์ด๋™ํ•˜๋Š”์นธ์— ํฐ์ด ์žˆ๋Š” ๊ฒฝ์šฐ
        p_cy,p_cx=p_pos
        p_ny,p_nx=dy+p_cy,dx+p_cx

        if not (0<=p_ny<8 and 0<=p_nx<8): # ํฐ์ด ๋ณด๋“œ์นธ์„ ๋„˜์–ด๊ฐ€๋Š” ๊ฒฝ์šฐ
            return
        # ํ‚น์„ ํฐ์œ„์น˜๋กœ ํฐ์€ ์ƒˆ๋กœ์šด์œ„์น˜๋กœ ์ด๋™
        k_pos=p_pos
        p_pos=(p_ny,p_nx)
    else:
        k_pos=(k_ny,k_nx)    



def solution():
    global k_pos, p_pos
    k_pos,p_pos,cases=map(str,input().split())

    k_pos=board_to_pos(k_pos)
    p_pos=board_to_pos(p_pos)

    for _ in range(int(cases)):
        unit_move(input().strip())

    print(pos_to_board(k_pos))
    print(pos_to_board(p_pos))

    pass
if __name__=="__main__": # ์‹คํ–‰๋˜๋Š” ๋ถ€๋ถ„
    solution()
    pass