poj 2339 Rock, Scissors, Paper

21 篇文章 0 订阅

题目来源:http://poj.org/problem?id=2339

小模拟,注意字母S的大小,为此wa了几次!

#include <iostream>
#include <cstring>
#include <cstdio>

using namespace std;

const int MAXN = 110;

int main()
{
    char Graph1[MAXN][MAXN], Graph2[MAXN][MAXN];
    int T, row, col, days, i, j;
    scanf("%d", &T);
    while(T--)
    {
        scanf("%d %d %d", &row, &col, &days);
        memset(Graph1, 0, sizeof(Graph1));
        memset(Graph2, 0, sizeof(Graph2));
        for(i = 0; i < row; ++i)
        {
            scanf("%s", Graph1[i]);
            for(j = 0; j < col; ++j)
                Graph2[i][j] = Graph1[i][j];
            Graph2[i][j] = '\0';
        }
        while(days--)//处理这几天的变化状态
        {
            for(i = 0; i < row; ++i)
            {
                for(j = 0; j < col; ++j)
                {
                    switch(Graph1[i][j])
                    {
                    case 'R'://判断R的上下左右是否为S,如果是,则用R替换掉S,以下类似
                        if(j-1 >= 0 && Graph1[i][j-1] == 'S')
                            Graph2[i][j-1] = 'R';
                        if(j+1 < col && Graph1[i][j+1] == 'S')
                            Graph2[i][j+1] = 'R';
                        if(i-1 >= 0 && Graph1[i-1][j] == 'S')
                            Graph2[i-1][j] = 'R';
                        if(i+1 < row && Graph1[i+1][j] == 'S')
                            Graph2[i+1][j] = 'R';
                            break;
                    case 'S':
                        if(j-1 >= 0 && Graph1[i][j-1] == 'P')
                            Graph2[i][j-1] = 'S';
                        if(j+1 < col && Graph1[i][j+1] == 'P')
                            Graph2[i][j+1] = 'S';
                        if(i-1 >= 0 && Graph1[i-1][j] == 'P')
                            Graph2[i-1][j] = 'S';
                        if(i+1 < row && Graph1[i+1][j] == 'P')
                            Graph2[i+1][j] = 'S';
                        break;
                    case 'P':
                        if(j-1 >= 0 && Graph1[i][j-1] == 'R')
                            Graph2[i][j-1] = 'P';
                        if(j+1 < col && Graph1[i][j+1] == 'R')
                            Graph2[i][j+1] = 'P';
                        if(i-1 >= 0 && Graph1[i-1][j] == 'R')
                            Graph2[i-1][j] = 'P';
                        if(i+1 < row && Graph1[i+1][j] == 'R')
                            Graph2[i+1][j] = 'P';
                        break;
                    default:
                        break;
                    }

                }
            }
            for(i = 0; i < row; ++i)
                strcpy(Graph1[i], Graph2[i]);
        }
        for(i = 0; i < row; ++i)
            printf("%s\n", Graph1[i]);
        if(T)
            printf("\n");
    }
    return 0;
}


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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值