0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

paizaラーニング問題集「STEP1移動が可能かの判定・方角」を解いてみた

Posted at

▼考え方

現在の座標と1マス移動する方角の3つを関数に渡して、移動が可能かどうかを判定し出力します。解答コードの考え方と私のものはほぼ一緒でした。

▼コード

H,W,sy,sx,m = input().split()

S = [list(input()) for _ in range(int(H))]

# npc: 移動が可能かどうかを判定し出力する関数
def npc(ny,nx,d):
    
    if d == "N":
        ny -= 1
    elif d == "S":
        ny += 1
    elif d == "W":
        nx -= 1
    else:
        nx += 1
      
    if (ny <= -1 or ny >= int(H)) or (nx <= -1  or nx >= int(W)):
        print("No")
    elif S[ny][nx] == "#":
        print("No")
    else:
        print("Yes")

npc(int(sy),int(sx),m)
0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?