#include<stdio.h>
#include<string.h>
#include<iostream>
using namespace std;
char s[5][5];
int main()
{
int x,y,flag=1;
char c;
for(int i=0;i<5;i++)
{
for(int j=0;j<5;j++)
if((s[i][j]=getchar())==' ')
{x=i;y=j;}
getchar();
}
while((c=getchar())!='0')
{
switch(c)
{
case 'A':
if(x-1>=0)
{s[x][y]=s[x-1][y];x--;}
else
flag=0;
break;
case 'B':
if(x+1<5)
{s[x][y]=s[x+1][y];x++;}
else
flag=0;
break;
case 'L':
if(y-1>=0)
{s[x][y]=s[x][y-1];y--;}
else
flag=0;
break;
case 'R':
if(y+1<5)
{s[x][y]=s[x][y+1];y++;}
else
flag=0;
break;
default:
flag=0;
break;
}
}
s[x][y]=' ';
if(flag)
for(int i=0;i<5;i++)
{
for(int j=0;j<5;j++)
printf("%c",s[i][j]);
printf("\n");
}
else
printf("This puzzle has no configuration.\n");
return 0;
}
UVa227 Puzzle
最新推荐文章于 2022-01-12 05:02:47 发布