x3-5

https://vjudge.net/problem/UVA-227

ps:此题格式很重要多次PE;

#include <iostream>
#include<cstring>
#include<cstdio>
using namespace std;
char maze[8][8];
int x,y,flag;
void up(){
    if(x-1>=1){
        maze[x][y]=maze[x-1][y];
        x--;
        maze[x][y]=' ';
    }
    else{
        flag=1;
        printf("This puzzle has no final configuration.\n");
    }
}
void down(){
    if(x+1<=5){
        maze[x][y]=maze[x+1][y];
        x++;
        maze[x][y]=' ';
    }
    else{
        flag=1;
        printf("This puzzle has no final configuration.\n");
    }
}
void le(){
    if(y-1>=1){
        maze[x][y]=maze[x][y-1];
        y--;
        maze[x][y]=' ';
    }
    else{
        flag=1;
        printf("This puzzle has no final configuration.\n");
    }
}
void ri(){
    if(y+1<=5){
        maze[x][y]=maze[x][y+1];
        y++;
        maze[x][y]=' ';
    }
    else{
        flag=1;
        printf("This puzzle has no final configuration.\n");
    }
}
int main()
{
    int kase=0;
    while(true){
        flag=0;
        for(int i=1; i<=5; i++) {
            for(int j=1;j<=5;j++){
                scanf("%c",&maze[i][j]);
                if(maze[i][j]=='Z')
                    exit(0);
                if(maze[i][j]==' '){
                    x=i;y=j;
                }
            }
            getchar();//吸收每行的换行
        }
        int indx=0;
        char c[1000],ty;
        while((ty=getchar())!='0'){  //指令只有遇到0才停
            if(ty=='A'||ty=='B'||ty=='L'||ty=='R')//排除空格,换行等
            c[indx++]=ty;
        }
        if(!kase)
        printf("Puzzle #%d:\n",++kase);//格式
        else printf("\nPuzzle #%d:\n",++kase);
        //int len = strlen(c);
        for(int i = 0; i < indx ;i++){
            if(flag)break;
            if(c[i]=='A')up();
            else if(c[i]=='B')down();
            else if (c[i]=='L') le();
            else ri();
        }
        if(!flag){
            for(int i=1; i<=5; i++) {
                for(int j=1;j<=5;j++){
                    printf("%c",maze[i][j]);
                    if(j!=5)
                    printf(" ");
                }
                printf("\n");
            }
        }

        getchar();//吸收最后的换行
    }
    return 0;
}
/*
TRGSJ
XDOKI
M VLN
WPABE
UQHCF
ARRBBL0
ABCDE
FGHIJ
KLMNO
PQRS 
TUVWX
AAA
LLLL0
ABCDE
FGHIJ
KLMNO
PQRS 
TUVWX
AAAAABBRRRLL0
Z
*/

 

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值