DSTJZ


私信TA

用户名:dotcpp0721777

访问量:4443

签 名:

天下难事,必作于易;天下大事,必作于细。

等  级
排  名 50
经  验 10992
参赛次数 13
文章发表 312
年  龄 18
在职情况 学生
学  校 狗熊岭23届毕业生
专  业

  自我简介:

TA的其他文章

java--study||O.o
浏览:22
java--study||O.o
浏览:19
java--study||O.o
浏览:21


参考代码:

#每个草丛只能是1个'#'或2个'#'
dx = (-1, 0, 1, 0)
dy = (0, -1, 0, 1)


def f(x, y):
    map[x][y] = '.'
    for d in range(4):
        tx, ty = x + dx[d], y + dy[d]
        if 0 <= tx < row and 0 <= ty < column and map[tx][ty] == '#':
            map[tx][ty] = '.'
            return

row, column = map(int, input().split())
map = [list(input().strip()) for _ in range(row)]
res = 0
for i in range(row):
    for j in range(column):
        if map[i][j] == '#':
            f(i, j)
            res += 1
print(res)


 

0.0分

0 人评分

看不懂代码?想转换其他语言的代码? 或者想问其他问题? 试试问问AI编程助手,随时响应你的问题:

编程语言转换万能编程问答  

代码解释器

代码纠错

SQL生成与解释

  评论区