【マップの扱い 3】マップの判定・縦横斜め Python3編
https://paiza.jp/works/mondai/b_rank_new_level_up_problems/python3/b_rank_new_level_up_problems__get_row_col/result?token=f946cdb7df7de4fa1a640fe1af7949fd
code:py
H, W = map(int, input().split())
lines = []
for _ in range(H):
line = char for char in input()
lines.append(line)
y, x = map(int, input().split())
# x列を反転
for i in range(H):
# linesyx以外を反転
if not i == y:
if linesix == '#':
linesix = '.'
else:
linesix = '#'
# y行を反転
# linesyxを反転
for index in range(W):
if linesyindex == '#':
linesyindex = '.'
else:
linesyindex = '#'
# 左斜め上を反転
poit = 1
for _ in range(H):
if y - poit >= 0 and x - poit >= 0:
if linesy - poitx - poit == '#':
linesy - poitx - poit = '.'
else:
linesy - poitx - poit = '#'
# 右斜め上を反転
if y - poit >= 0 and x + poit < W:
if linesy - poitx + poit == '#':
linesy - poitx + poit = '.'
else:
linesy - poitx + poit = '#'
# 左斜め下を反転
if y + poit < H and x - poit >= 0:
if linesy + poitx - poit == '#':
linesy + poitx - poit = '.'
else:
linesy + poitx - poit = '#'
# 右斜め下を反転
if y + poit < H and x + poit < W:
if linesy + poitx + poit == '#':
linesy + poitx + poit = '.'
else:
linesy + poitx + poit = '#'
# カウントして次のポインターへ
poit += 1
# 結果出力
for line in lines:
print(''.join(line))