poj_2339

参考: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

 1 #include <iostream>
 2 #include <cstdio>
 3 #include <cstring>
 4 using namespace std;
 5 const int N=105;
 6 char old[N][N],news[N][N];//old存旧数组,news存新数组
 7 int dir[2][4]={{-1,0,1,0},{0,1,0,-1}};//周围四个格
 8 int r,l,n;
 9 int lawful(int x,int y)//判断是否超出边界
10 {
11     if (x>=0&&x<r&&y>=0&&y<l)
12     {
13         return 1;
14     }
15     else
16     {
17         return 0;
18     }
19 }
20 char change(int x,int y)//依据规则改变
21 {
22     for (int i=0;i<4;i++)
23     {
24         int xx=x+dir[0][i];
25         int yy=y+dir[1][i];
26         if (lawful(xx,yy))
27         {
28             if (old[xx][yy]=='R'&&old[x][y]=='S')
29             {
30                 return 'R';
31             }
32             else if (old[xx][yy]=='S'&&old[x][y]=='P')
33             {
34                 return 'S';
35             }
36             else if (old[xx][yy]=='P'&&old[x][y]=='R')
37             {
38                 return 'P';
39             }
40         }
41     }
42     return old[x][y];
43 }
44 int main()
45 {
46     int t;
47 //    freopen("bin.txt","r",stdin);
48     while (cin>>t)
49     {
50         while (t--)
51         {
52             cin>>r>>l>>n;
53             memset(old,0,sizeof(old));
54             memset(news,0,sizeof(news));
55             for (int i=0;i<r;i++)
56             {
57                 for (int j=0;j<l;j++)
58                 {
59                     cin>>old[i][j];
60                 }
61             }
62             for (int i=0;i<n;i++)
63             {
64                 for (int j=0;j<r;j++)
65                 {
66                     for (int k=0;k<l;k++)
67                     {
68                         news[j][k]=change(j,k);//更新news
69                     }
70                 }
71                 memcpy(old,news,sizeof(news));
72             }
73             for (int i=0;i<r;i++)
74             {
75                 for (int j=0;j<l;j++)
76                 {
77                     cout<<old[i][j];
78                 }
79                 cout<<endl;
80             }
81             cout<<endl;
82         }
83     }
84 
85     return 0;
86 }

 

转载于:https://www.cnblogs.com/hemeiwolong/p/9496932.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值