参考:https://blog.csdn.net/yzl_rex/article/details/7600906

https://blog.csdn.net/acm_JL/article/details/50200355

https://blog.csdn.net/qq_35040828/article/details/71123521

https://zhidao.baidu.com/question/49762862.html

 #include <iostream>
#include <cstdio>
#include <cstring>
using namespace std;
const int N=;
char old[N][N],news[N][N];//old存旧数组,news存新数组
int dir[][]={{-,,,},{,,,-}};//周围四个格
int r,l,n;
int lawful(int x,int y)//判断是否超出边界
{
if (x>=&&x<r&&y>=&&y<l)
{
return ;
}
else
{
return ;
}
}
char change(int x,int y)//依据规则改变
{
for (int i=;i<;i++)
{
int xx=x+dir[][i];
int yy=y+dir[][i];
if (lawful(xx,yy))
{
if (old[xx][yy]=='R'&&old[x][y]=='S')
{
return 'R';
}
else if (old[xx][yy]=='S'&&old[x][y]=='P')
{
return 'S';
}
else if (old[xx][yy]=='P'&&old[x][y]=='R')
{
return 'P';
}
}
}
return old[x][y];
}
int main()
{
int t;
// freopen("bin.txt","r",stdin);
while (cin>>t)
{
while (t--)
{
cin>>r>>l>>n;
memset(old,,sizeof(old));
memset(news,,sizeof(news));
for (int i=;i<r;i++)
{
for (int j=;j<l;j++)
{
cin>>old[i][j];
}
}
for (int i=;i<n;i++)
{
for (int j=;j<r;j++)
{
for (int k=;k<l;k++)
{
news[j][k]=change(j,k);//更新news
}
}
memcpy(old,news,sizeof(news));
}
for (int i=;i<r;i++)
{
for (int j=;j<l;j++)
{
cout<<old[i][j];
}
cout<<endl;
}
cout<<endl;
}
} return ;
}

最新文章

  1. 适配iOS 10以及Xcode 8(转载)
  2. 【原】移动web页面使用字体的思考
  3. How To Handle a Loss of Confidence in Yourself
  4. 通过profiler对unity进行针对性优化
  5. select接收后台返回值的解决方案
  6. 【JQuery】jQuery.inArray 确定第一个参数在数组中的位置
  7. C#写文本日志帮助类(支持多线程)
  8. Java学习-011-创建文件实例及源代码
  9. 自我提升mysql
  10. kafka的一些名词
  11. Windows 窗体的.Net 框架绘图技术
  12. jQuery移除指定元素后的所有元素
  13. ubuntu15.10下sublime text3 无法输入中文解决办法
  14. Canvas rontate(旋转) 使用误区
  15. Linux进程的状态转换图
  16. hdu2108 Shape of HDU 极角排序判断多边形
  17. Emmet for Dreamweaver:HTML/CSS代码快速编写神器
  18. codeforces960G. Bandit Blues
  19. mysql Table &#39;user&#39; is marked as crashed and should be repaired
  20. python3-元类

热门文章

  1. Selenium2学习(九)-- 多窗口,句柄(handle)
  2. Linux文件压缩和解压缩命令
  3. MySQL的基础(优化)3
  4. 笨办法学Python(四十)
  5. GitLab 数据自动备份
  6. March 16 2017 Week 11 Thursday
  7. python3乱码问题:接口返回数据中文乱码问题解决
  8. 第一次在stack overflow回答问题
  9. python manage.py startapp app 时候报错No module named _sqlite3
  10. C++11之 Move semantics(移动语义)(转)