• 2339Rock, Scissors, Paper


    Description

    Bart's sister Lisa has created a new civilization on a two-dimensional grid. At the outset each grid location may be occupied by one of three life forms: Rocks, Scissors, or Papers. Each day, differing life forms occupying horizontally or vertically adjacent grid locations wage war. In each war, Rocks always defeat Scissors, Scissors always defeat Papers, and Papers always defeat Rocks. At the end of the day, the victor expands its territory to include the loser's grid position. The loser vacates the position. 
    Your job is to determine the territory occupied by each life form after n days.

    Input

    The first line of input contains t, the number of test cases. Each test case begins with three integers not greater than 100: r and c, the number of rows and columns in the grid, and n. The grid is represented by the r lines that follow, each with c characters. Each character in the grid is R, S, or P, indicating that it is occupied by Rocks, Scissors, or Papers respectively.

    Output

    For each test case, print the grid as it appears at the end of the nth day. Leave an empty line between the output for successive test cases.

    Sample Input

    2
    3 3 1
    RRR
    RSR
    RRR
    3 4 2
    RSPR
    SPRS
    PRSP
    

    Sample Output

    RRR
    RRR
    RRR
    
    RRRS
    RRSP
    RSPR
    #include<stdio.h>
    #include<stdlib.h>
    #include<string.h>
    #define R 101
    #define C 101
    int main(int argc, char const *argv[])
    {
    	int n,i,j,k;
    	int r,c,t;
        char yest[R][C];
        char to[R][C];
        scanf("%d",&n);
        while(n--)
        { 
          scanf("%d%d%d",&r,&c,&t);
          getchar();
          for(i=1;i<=r;i++)
          { 	
          	for(j=1;j<=c;j++)
          	scanf("%c",&yest[i][j]);
            getchar();
          }
          		
          for(k=0;k<t;k++)
          {
          	memset(to,0,sizeof(to));
          	for(i=1;i<=r;i++)
          		{
          			for(j=1;j<=c;j++)
          			{
          				if(yest[i][j]=='R')
          					{
                               if(yest[i-1][j]=='P'||yest[i+1][j]=='P'||yest[i][j-1]=='P'||yest[i][j+1]=='P')
                               	   to[i][j]='P';
                               	else to[i][j]=yest[i][j];
          			        }
          			    else if (yest[i][j]=='P')
          			    {
                             if(yest[i-1][j]=='S'||yest[i+1][j]=='S'||yest[i][j-1]=='S'||yest[i][j+1]=='S')
                               	   to[i][j]='S';
                               	else to[i][j]=yest[i][j];
          			    }
          			    else if(yest[i][j]=='S')
          			    {
          			    	if(yest[i-1][j]=='R'||yest[i+1][j]=='R'||yest[i][j-1]=='R'||yest[i][j+1]=='R')
                               	   to[i][j]='R';
                               	else to[i][j]=yest[i][j];
          			    }
          		    }
          		}
             for(i=1;i<=r;i++)
             	for(j=1;j<=c;j++)
             		yest[i][j]=to[i][j];
          }
          for(i=1;i<=r;i++)
          {
          	for(j=1;j<=c;j++)
          	{
          		printf("%c",to[i][j]);
          	}
          	printf("
    ");
          }
          printf("
    ");
        }
    
    	return 0;
    }

  • 相关阅读:
    地图 SDK 系列教程-在地图上展示指定区域
    [奇思妙想]下一个和微博、微信同级别的应用为是什么样的
    [办公自动化]EXCEL不大,但是保存很慢
    [奇思妙想]公共图书馆+快递
    [奇思妙想]“停哪了”
    [IT学习]阿铭Linux 微信公众号 每日一题 解析
    [IT学习]GIT 学习
    [故障处理]西部数据wd elements xp 无法识别
    [奇思妙想]无人机
    [IT学习]跟阿铭学linux(第3版)
  • 原文地址:https://www.cnblogs.com/kuroko-ghh/p/9363352.html
Copyright © 2020-2023  润新知