ABOUT ME

-

Today
-
Yesterday
-
Total
-
  • [๋ฐฑ์ค€] 1063 ํ‚น with Python
    PS 2021. 12. 29. 23:16
    728x90
    ๋ฐ˜์‘ํ˜•

    ๐Ÿ“Œ BOJ 1063 ํ‚น

    ๐Ÿ’ก ์กฐ๊ฑด

    1. ์ฒด์ŠคํŒ์˜ ํฌ๊ธฐ๋Š” 8*8

    2. ์ฒด์ŠคํŒ์—์„œ์˜ ๋ง์˜ ์œ„์น˜๋Š” ์•ŒํŒŒ๋ฒณ ํ•˜๋‚˜์™€ ์ˆซ์ž ํ•˜๋‚˜๋กœ ๊ตฌ์„ฑ๋˜์–ด ์žˆ๋‹ค.
      ์•ŒํŒŒ๋ฒณ์€ ์—ด(column), ์ˆซ์ž๋Š” ํ–‰(row)์„ ์ƒ์ง•ํ•œ๋‹ค.
      ์•ŒํŒŒ๋ฒณ์€ AH, ์ˆซ์ž๋Š” 18๊นŒ์ง€์ด๋‹ค.

    3. ํ‚น์ด ์›€์ง์ผ ์ˆ˜ ์žˆ๋Š” ๋ฐฉ๋ฒ•์€ 8๊ฐ€์ง€๊ฐ€ ์žˆ์œผ๋ฉฐ, ๋ฌธ์ œ์— ์ œ์‹œ๋˜์–ด ์žˆ๋‹ค.

    4. ์ฒด์ŠคํŒ์— ์žˆ๋Š” ๋Œ์€ ํ‚น์ด ์›€์ง์ธ ๋ฐฉํ–ฅ์œผ๋กœ ๊ฐ™์ด ์›€์ง์ธ๋‹ค.
      ์ฒด์ŠคํŒ์ด๋‚˜ ๋Œ์ด ์ž…๋ ฅ์—์„œ ์ฃผ์–ด์ง„๋Œ€๋กœ ์›€์ง์ด๋‹ค๊ฐ€ ๋ฐ–์œผ๋กœ ๋‚˜๊ฐˆ ๊ฒฝ์šฐ, ๊ทธ ์ด๋™์€ ๊ฑด๋„ˆ ๋›ด๋‹ค.

    5. ์ฒซ์งธ ์ค„์— ํ‚น์˜ ๋งˆ์ง€๋ง‰ ์œ„์น˜, ๋‘˜์งธ ์ค„์— ๋Œ์˜ ๋งˆ์ง€๋ง‰ ์œ„์น˜๋ฅผ ์ถœ๋ ฅํ•œ๋‹ค.

    6. ๊ตฌํ˜„, ์‹œ๋ฎฌ๋ ˆ์ด์…˜์˜ ๋ฌธ์ œ

    ๐Ÿ–ฅ ์†Œ์Šค ์ฝ”๋“œ

    from sys import stdin
    
    k, s, n = stdin.readline().rstrip().split()
    pos_k = [ord(k[0]), int(k[1])]
    pos_s = [ord(s[0]), int(s[1])]
    
    for _ in range(int(n)):
        com = stdin.readline().rstrip()
        if com == 'R':
            if 64 < pos_k[0] + 1 < 73:
                pos_k[0] += 1
    
                if pos_k == pos_s:
                    if 64 < pos_s[0] + 1 < 73:
                        pos_s[0] += 1
                    else:
                        pos_k[0] -= 1
    
        elif com == 'L':
            if 64 < pos_k[0] - 1 < 73:
                pos_k[0] -= 1
    
                if pos_k == pos_s:
                    if 64 < pos_s[0] - 1 < 73:
                        pos_s[0] -= 1
                    else:
                        pos_k[0] += 1
    
        elif com == 'B':
            if 0 < pos_k[1] - 1 < 9:
                pos_k[1] -= 1
    
                if pos_k == pos_s:
                    if 0 < pos_s[1] - 1 < 9:
                        pos_s[1] -= 1
                    else:
                        pos_k[1] += 1
    
        elif com == 'T':
            if 0 < pos_k[1] + 1 < 9:
                pos_k[1] += 1
    
                if pos_k == pos_s:
                    if 0 < pos_s[1] + 1 < 9:
                        pos_s[1] += 1
                    else:
                        pos_k[1] -= 1
    
        elif com == 'RT':
            if 0 < pos_k[1] + 1 < 9 and 64 < pos_k[0] + 1 < 73:
                pos_k[0] += 1
                pos_k[1] += 1
    
                if pos_k == pos_s:
                    if 0 < pos_s[1] + 1 < 9 and 64 < pos_s[0] + 1 < 73:
                        pos_s[0] += 1
                        pos_s[1] += 1
                    else:
                        pos_k[0] -= 1
                        pos_k[1] -= 1
    
        elif com == 'LT':
            if 0 < pos_k[1] + 1 < 9 and 64 < pos_k[0] - 1 < 73:
                pos_k[0] -= 1
                pos_k[1] += 1
    
                if pos_k == pos_s:
                    if 0 < pos_s[1] + 1 < 9 and 64 < pos_s[0] - 1 < 73:
                        pos_s[0] -= 1
                        pos_s[1] += 1
                    else:
                        pos_k[0] += 1
                        pos_k[1] -= 1
    
        elif com == 'RB':
            if 0 < pos_k[1] - 1 < 9 and 64 < pos_k[0] + 1 < 73:
                pos_k[0] += 1
                pos_k[1] -= 1
    
                if pos_k == pos_s:
                    if 0 < pos_s[1] - 1 < 9 and 64 < pos_s[0] + 1 < 73:
                        pos_s[0] += 1
                        pos_s[1] -= 1
                    else:
                        pos_k[0] -= 1
                        pos_k[1] += 1
    
        elif com == 'LB':
            if 0 < pos_k[1] - 1 < 9 and 64 < pos_k[0] - 1 < 73:
                pos_k[0] -= 1
                pos_k[1] -= 1
    
                if pos_k == pos_s:
                    if 0 < pos_s[1] - 1 < 9 and 64 < pos_s[0] - 1 < 73:
                        pos_s[0] -= 1
                        pos_s[1] -= 1
                    else:
                        pos_k[0] += 1
                        pos_k[1] += 1
    
    
    print('{}'.format(chr(pos_k[0]) + str(pos_k[1])))
    print('{}'.format(chr(pos_s[0]) + str(pos_s[1])))

    ๐Ÿ”– ์˜ˆ์ œ ๋ฐ ์‹คํ–‰๊ฒฐ๊ณผ

    ์˜ˆ์ œ

    A1 A2 5
    B
    L
    LB
    RB
    LT

    ์‹คํ–‰๊ฒฐ๊ณผ

    A1
    A2

    โŒจ๏ธ ๋ฌธ์ œ ํ’€์ด

    1. ์ฒซ ์œ„์น˜๋ฅผ ์ž…๋ ฅ ๋ฐ›๊ณ , ์ฃผ์–ด์ง„ ์ž…๋ ฅ์˜ ํšŸ์ˆ˜๋งŒํผ ์ด๋™๋ช…๋ น์„ ๋ฐ›์•„ ์ฒ˜๋ฆฌํ•˜๋ฉด ๋œ๋‹ค.

      • ๋Œ€๋ฌธ์ž A~H ๋Š” ์•„์Šคํ‚ค ์ฝ”๋“œ ์ˆซ์ž๋ฅผ ์‚ฌ์šฉํ•˜์—ฌ ์ฒ˜๋ฆฌ๋ฅผ ํ•˜๋Š” ๊ฒƒ์ด ํ›จ์”ฌ ํŽธํ•˜๋‹ค.
    2. ๊ฐ ์ปค๋งจ๋“œ๋งˆ๋‹ค ์›€์ง์ด๋Š” ์ขŒํ‘œ๋ฅผ ์ˆ˜์ •ํ•ด์ฃผ๋ฉด์„œ ์•„๋ž˜์˜ ํ™•์ธ์‚ฌํ•ญ์„ ์ฒดํฌํ•œ๋‹ค.

      • ํ‚น์€ ์›€์ง์ด์ง€ ๋ชปํ•˜๋Š”๋ฐ ๋Œ์ด ์›€์ง์ผ ์ˆ˜ ์žˆ๋Š” ๊ฒฝ์šฐ๋Š” ๊ทธ๋ƒฅ ๋„˜์–ด๊ฐ„๋‹ค.
      • ๋Œ์€ ์›€์ง์ด์ง€ ๋ชปํ•˜๋Š”๋ฐ ํ‚น์ด ์›€์ง์ผ ์ˆ˜ ์žˆ๋Š” ๊ฒฝ์šฐ๋Š” ๊ทธ๋ƒฅ ๋„˜์–ด๊ฐ„๋‹ค.
      • ์›€์ง์ด์ง€ ๋ชปํ•˜๋Š” ๊ณณ์ด๋ผ๋ฉด ๊ฐ€๋ณ๊ฒŒ ๋ฌด์‹œํ•˜๊ณ  ๋‹ค์Œ์œผ๋กœ ๋„˜์–ด๊ฐ„๋‹ค.

    ๐Ÿ’พ ๋Š๋‚€์ 

    1. ์œ„์น˜๋ฅผ ์ €์žฅํ•˜๋Š” ์•ŒํŒŒ๋ฒณ๊ณผ, ์ˆซ์ž๋ฅผ ๊ณ„์‚ฐํ•˜์—ฌ ์ƒํƒœ๋ฅผ ์ €์žฅํ•˜๋ฉด ๋˜๋Š” ๋ฌธ์ œ์˜€๋‹ค.
    2. ์—ด๊ณผ ํ–‰์— ํ•ด๋‹นํ•˜๋Š” ์•ŒํŒŒ๋ฒณ๊ณผ ์ˆซ์ž๋ฅผ ํ•ธ๋“ค๋งํ•˜์—ฌ ์ƒํƒœ๊ฐ€ ๋ณ€ํ™”ํ•  ๋•Œ ๊ฐ€๋Šฅํ•œ ์›€์ง์ž„์ธ์ง€ ์ฒดํฌํ•˜๋Š” ๋ถ€๋ถ„์ด
      ํ™•์‹คํžˆ ํ—ท๊ฐˆ๋ฆฌ๊ณ  ์–ด๋ ค์› ๋‹ค.
    ๋ฐ˜์‘ํ˜•

    ๋Œ“๊ธ€

Designed by Tistory.