#34959: Python解


popo0816@apps.ntpc.edu.tw (壽溥謙)

學校 : 龍華科技大學
編號 : 214606
來源 : [59.120.140.251]
最後登入時間 :
2024-10-27 15:07:55
e605. 10189 - Minesweeper -- UVA | From: [118.160.82.150] | 發表日期 : 2023-04-29 16:18

Case = 0
while True:
Case += 1
# input
Line, Amount = map(int, input().split())
Array = [["." for i in range(Amount)] for j in range(Line)]
for i in range(int(Line)):
Array[i] = list(input())

if Line == 0 and Amount == 0:
break
# do something here
for i in range(Line):
for j in range(Amount):
if Array[i][j] != "*":
a = 0
for m in range(i - 1, i + 2):
for n in range(j - 1, j + 2):
if (0 <= m < Line) and (0 <= n < Amount) and (m != i and n != j):
if Array[m][n] is "*":
a += 1
if 0 <= i + 1 < Line:
if Array[i + 1][j] is "*":
a += 1
if 0 <= i - 1 < Line:
if Array[i - 1][j] is "*":
a += 1
if 0 <= j + 1 < Line:
if Array[i][j + 1] is "*":
a += 1
if 0 <= j - 1 < Line:
if Array[i][j - 1] is "*":
a += 1
Array[i][j] = a
# output
print(f"Field #{Case}:")
for i in range(Line):
for j in range(Amount):
print(Array[i][j], end="")
print("")
 
ZeroJudge Forum