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?

Python3: paizaラーニング問題集「マップの判定・縦横」やってみた

Last updated at Posted at 2024-11-12

なんとなく解き方あったなと思ったのでやってみました。

マップのある場所の四方を調べる的なことなので、マップの廻りを何かで取り囲んでやると場合分けが少なくなる的なことです。

H, W = map(int, input().split())

BORDERED = tuple(
    (True,) * (W + 2)
        if j == 0
        or j == H + 1
        else
    (True
     , *(i == "#" for i in input())
     , True
     )
    for j in range(H + 2)
    )
    
every_side_surrounded = (
    (j - 1, i - 1)
    for j in range(1, H + 1)
    for i in range(1, W + 1)
    if BORDERED[j - 1][i]
    and BORDERED[j + 1][i]
    and BORDERED[j][i - 1]
    and BORDERED[j][i + 1]
    )

for p in every_side_surrounded:
    print(p[0], p[1])
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?