poj2339

简单题

View Code
#include <iostream>
#include
<cstdio>
#include
<cstdlib>
#include
<cstring>
using namespace std;

#define maxn 105

int n, m, d;
char map[2][maxn][maxn];
int dir[4][2] =
{
{
1, 0 },
{
0, 1 },
{
-1, 0 },
{
0, -1 } };

void input()
{
scanf(
"%d%d%d", &n, &m, &d);
getchar();
for (int i = 1; i <= n; i++)
{
for (int j = 1; j <= m; j++)
map[
0][i][j] = getchar();
getchar();
}
}

char getop(char a)
{
if (a == 'R')
return 'P';
if (a == 'P')
return 'S';
return 'R';
}

void work()
{
for (int i = 0; i < d; i++)
{
for (int j = 1; j <= n; j++)
for (int k = 1; k <= m; k++)
{
char ch = getop(map[i & 1][j][k]);
map[(i
+ 1) & 1][j][k] = map[i & 1][j][k];
for (int l = 0; l < 4; l++)
if (map[i & 1][j + dir[l][0]][k + dir[l][1]] == ch)
{
map[(i
+ 1) & 1][j][k] = ch;
break;
}
}
}
}

void print()
{
int x = d & 1;
for (int i = 1; i <= n; i++)
{
for (int j = 1; j <= m; j++)
putchar(map[x][i][j]);
putchar(
'\n');
}
}

int main()
{
//freopen("t.txt", "r", stdin);
int t;
scanf(
"%d", &t);
while (t--)
{
input();
work();
print();
if (t > 0)
putchar(
'\n');
}
return 0;
}

你可能感兴趣的:(poj)