DSTJZ


私信TA

用户名:dotcpp0721777

访问量:4712

签 名:

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

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

  自我简介:

TA的其他文章


参考代码:

from copy import deepcopy
dx = (-1, 0, 1, 0)
dy = (0, -1, 0, 1)


def judge(x, y):
    for d in range(4):
        tx, ty = x + dx[d], y + dy[d]
        if 0 <= tx < row and 0 <= ty < column:
            if arr[x][y] == 'R' and arr[tx][ty] == 'S':
                temp[tx][ty] = 'R'
            if arr[x][y] == 'S' and arr[tx][ty] == 'P':
                temp[tx][ty] = 'S'
            if arr[x][y] == 'P' and arr[tx][ty] == 'R':
                temp[tx][ty] = 'P'
    return


row, column, n = map(int, input().split())
arr = [list(input().strip()) for _ in range(row)]
temp = deepcopy(arr)

for k in range(n):
    for i in range(row):
        for j in range(column):
            judge(i, j)
    arr = deepcopy(temp)#本来我写的是交换两个列表引用,不对!
for i in range(row):
    for j in range(column):
        print(arr[i][j], end="")
    print()


 

0.0分

0 人评分

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

编程语言转换

万能编程问答  

代码解释器

代码纠错

SQL生成与解释

  评论区