参考代码:
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 人评分
C语言程序设计教程(第三版)课后习题9.1 (Java代码)浏览:471 |
【密码】 (C语言代码)浏览:333 |
简单的a+b (C语言代码)浏览:573 |
C语言程序设计教程(第三版)课后习题1.5 (C语言代码)浏览:464 |
C语言程序设计教程(第三版)课后习题8.3 (C语言代码)浏览:575 |
WU-输出九九乘法表 (C++代码)浏览:1671 |
Wu-求圆的面积 (C++代码)浏览:1892 |
求圆的面积 (C语言代码)浏览:1670 |
P1000 (C语言代码)浏览:877 |
蚂蚁感冒 (C语言代码)浏览:1333 |