HDU 4213 模拟

推箱子 

模拟一下就好了 

水题


#include "stdio.h"
#include "string.h"
#include "math.h"
#include "stdlib.h"

int n,m;
char str[101][101];

int judge()
{
    int i,j;
    for (i=0;i<n;i++)
        for (j=0;j<m;j++)
            if (str[i][j]=='+' || str[i][j]=='b' || str[i][j]=='W') return 0;

    return 1;
}



int main()
{
    int Case,i,flag,j,x,y;
    char op[101];
    Case=0;
    while (scanf("%d%d",&n,&m)!=EOF)
    {
        if (n==0 && m==0) break;

        Case++;
        getchar();

        for (i=0;i<n;i++)
        {
            gets(str[i]);
            for (j=0;j<m;j++)
                if (str[i][j]=='w' || str[i][j]=='W')
                {
                    x=i;
                    y=j;
                }
        }

        flag=0;
        gets(op);

        for (i=0;op[i];i++)
        {
            if (judge()==1) 
            {
                flag=1;
                break;
            }
            if (op[i]=='U')
            {
                if (str[x-1][y]=='#') continue;

                if (str[x-1][y]=='.' )
                {
                    str[x-1][y]='w';
                    if (str[x][y]=='w') str[x][y]='.';
                    else str[x][y]='+';
                    x--;
                    continue;
                }

                if (str[x-1][y]=='+')
                {
                    str[x-1][y]='W';
                    if (str[x][y]=='w') str[x][y]='.';
                    else str[x][y]='+';
                    x--;
                    continue;
                }

                if (str[x-1][y]=='b' || str[x-1][y]=='B')
                {
                    if (str[x-2][y]=='b' || str[x-2][y]=='B' || str[x-2][y]=='#') continue;

                    if (str[x-2][y]=='.') str[x-2][y]='b'; else str[x-2][y]='B';

                    if (str[x-1][y]=='b') str[x-1][y]='w'; else str[x-1][y]='W';

                    if (str[x][y]=='w') str[x][y]='.'; else str[x][y]='+';
                    x--;
                    continue;
                }
            }

            if (op[i]=='D')
            {
                if (str[x+1][y]=='#') continue;

                if (str[x+1][y]=='.' )
                {
                    str[x+1][y]='w';
                    if (str[x][y]=='w') str[x][y]='.';
                    else str[x][y]='+';
                    x++;
                    continue;
                }

                if (str[x+1][y]=='+')
                {
                    str[x+1][y]='W';
                    if (str[x][y]=='w') str[x][y]='.';
                    else str[x][y]='+';
                    x++;
                    continue;
                }

                if (str[x+1][y]=='b' || str[x+1][y]=='B')
                {
                    if (str[x+2][y]=='b' || str[x+2][y]=='B' || str[x+2][y]=='#') continue;

                    if (str[x+2][y]=='.') str[x+2][y]='b'; else str[x+2][y]='B';

                    if (str[x+1][y]=='b') str[x+1][y]='w'; else str[x+1][y]='W';

                    if (str[x][y]=='w') str[x][y]='.'; else str[x][y]='+';
                    x++;
                    continue;
                }
            }

            if (op[i]=='L')
            {
                if (str[x][y-1]=='#') continue;

                if (str[x][y-1]=='.' )
                {
                    str[x][y-1]='w';
                    if (str[x][y]=='w') str[x][y]='.';
                    else str[x][y]='+';
                    y--;
                    continue;
                }

                if (str[x][y-1]=='+')
                {
                    str[x][y-1]='W';
                    if (str[x][y]=='w') str[x][y]='.';
                    else str[x][y]='+';
                    y--;
                    continue;
                }

                if (str[x][y-1]=='b' || str[x][y-1]=='B')
                {
                    if (str[x][y-2]=='b' || str[x][y-2]=='B' || str[x][y-2]=='#') continue;

                    if (str[x][y-2]=='.') str[x][y-2]='b'; else str[x][y-2]='B';

                    if (str[x][y-1]=='b') str[x][y-1]='w'; else str[x][y-1]='W';

                    if (str[x][y]=='w') str[x][y]='.'; else str[x][y]='+';
                    y--;
                    continue;
                }
            }

            if (op[i]=='R')
            {
                if (str[x][y+1]=='#') continue;

                if (str[x][y+1]=='.' )
                {
                    str[x][y+1]='w';
                    if (str[x][y]=='w') str[x][y]='.';
                    else str[x][y]='+';
                    y++;
                    continue;
                }

                if (str[x][y+1]=='+')
                {
                    str[x][y+1]='W';
                    if (str[x][y]=='w') str[x][y]='.';
                    else str[x][y]='+';
                    y++;
                    continue;
                }

                if (str[x][y+1]=='b' || str[x][y+1]=='B')
                {
                    if (str[x][y+2]=='b' || str[x][y+2]=='B' || str[x][y+2]=='#') continue;

                    if (str[x][y+2]=='.') str[x][y+2]='b'; else str[x][y+2]='B';

                    if (str[x][y+1]=='b') str[x][y+1]='w'; else str[x][y+1]='W';

                    if (str[x][y]=='w') str[x][y]='.'; else str[x][y]='+';
                    y++;
                    continue;
                }
            }
        } // for op

        if (judge()==1) flag=1;

        printf("Game %d: ",Case);
        if (flag==0)
            printf("incomplete\n");
        else 
            printf("complete\n");

        for (i=0;i<n;i++)
            puts(str[i]);

    }
    return 0;
}


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值