LoginSignup
1
0

More than 3 years have passed since last update.

マップの判定・縦横 Python3編やってみた(Bランク相当)

Last updated at Posted at 2020-08-20

昨日公開されたPaizaのAランクセットアップ。

コーディングした内容が保存されないので記録として。
現在Bランク。

コード

paiza_map.py

h,w = [int(i) for i in input().slit()]

board = [list(input()) for i in range(h)]



for i in range(h):
    for j in range(w):
        #左上の場合
        if i == 0 and j == 0:
            if board[0][1] == "#" and board[1][0] == "#":
                print(i,j)
        #右上の場合
        elif i == 0 and j == w-1:
            if board[0][j-1] == "#" and board[1][j] == "#":
                print(i,j)
        #左下の場合
        elif i == h-1 and j == 0 :
            if board[i][1] == "#" and board[i-1][0] == "#":
                print(i,j)
        #右下の場合
        elif i == h-1 and j == w-1:
            if board[i-1][j] == "#" and board[i][j-1] == "#":
                print(i,j)
        #上の場合
        elif i == 0:
            if board[0][j-1] == "#" and board[0][j+1] == "#" and board[1][j] == "#":
                print(i,j)
        #下の場合
        elif i == h-1:
            if board[i][j-1] == "#" and board[i][j+1] == "#" and board[i+1][j] == "#":
                print(i,j)
        #左の場合
        elif j == 0:
            if board[i+1][j] == "#" and board[i-1][j] == "#" and board[i][1] == "#":
                print(i,j)
        #右の場合
        elif j == w-1:
            if board[i+1][j] == "#" and board[i-1][j] == "#" and board[i][j-1] == "#":
                print(i,j)
        #それ以外
        else:
            if board[i+1][j] == "#" and board[i-1][j] == "#" and board[i][j-1] == "#" and board[i][j+1] == "#":
                print(i,j)

感想

分岐多めでめんどくさいけど、かなり簡単な部類。
予め整理して取り組めば10分余り位で溶ける問題。

参照

マップの判定・縦横 (paizaランク B 相当)

1
0
4

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
1
0