参考代码:
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语言训练-排序问题<2> (C++代码)(sort函数)浏览:1728 |
点我有惊喜!你懂得!浏览:1444 |
C语言训练-自守数问题 (C语言代码) long long浏览:1110 |
C二级辅导-等差数列 (C语言代码)浏览:630 |
永远的丰碑 (C语言代码)浏览:708 |
C语言程序设计教程(第三版)课后习题7.4 (Java代码)浏览:873 |
2006年春浙江省计算机等级考试二级C 编程题(2) (C语言代码)浏览:507 |
2003年秋浙江省计算机等级考试二级C 编程题(2) (C语言代码)浏览:563 |
回文串 (C语言代码)浏览:3115 |
C语言程序设计教程(第三版)课后习题5.8 (C语言代码)浏览:613 |