tj
2024-11-09 20:25:21
发布于:上海
0阅读
0回复
0点赞
#include <iostream>
#include <vector>
using namespace std;
int dx[4] = {0,1,0,-1};
int dy[4] = {1,0,-1,0};
bool win(char a, char b) {
if ((a == 'R' && b == 'S') || (a == 'S' && b == 'P') || (a == 'P' && b == 'R')) {
return true;
}
return false;
}
int main() {
int r, c, n;
cin >> r >> c >> n;
vector<vector<char>> matrix(r, vector<char>(c));
for (int i = 0; i < r; i++) {
for (int j = 0; j < c; j++) {
cin >> matrix[i][j];
}
}
for (int k = 0; k < n; k++) {
vector<vector<char>> newMatrix = matrix;
for (int i = 0; i < r; i++) {
for (int j = 0; j < c; j++) {
for (int d = 0; d < 4; d++) {
int newX = i + dx[d];
int newY = j + dy[d];
if (newX >= 0 && newX < r && newY >= 0 && newY < c && win(matrix[i][j], matrix[newX][newY])) {
newMatrix[newX][newY] = matrix[i][j];
}
}
}
}
matrix = newMatrix;
}
for (int i = 0; i < r; i++) {
for (int j = 0; j < c; j++) {
cout << matrix[i][j];
}
cout << endl;
}
return 0;
}
这里空空如也
有帮助,赞一个