This file contains ambiguous Unicode characters that may be confused with others in your current locale. If your use case is intentional and legitimate, you can safely ignore this warning. Use the Escape button to highlight these characters.
#include<bits/stdc++.h>
usingnamespacestd;
intmain(){
chars[5][5];
charc;
intcnt=0;
while(true){
for(inti=0;i<5;i++){//输入网格
for(intj=0;j<5;j++){
scanf("%c",&s[i][j]);
if(s[0][0]=='Z')return0;//检查字母‘Z’
}
getchar();
}
//找到空格的位置,用 i、j 记录
inti,j,flag=0,flag2=0;
for(i=0;i<5;i++){
for(j=0;j<5;j++){
if(s[i][j]==''){
flag=1;
break;
}
}
if(flag)break;
}
while((c=getchar())!='0'){//做出操作
if(c=='A'&&i-1>=0){
s[i][j]=s[i-1][j];
s[i-1][j]='';
i-=1;//更新空格的位置,下同
}elseif(c=='B'&&i+1<5){
s[i][j]=s[i+1][j];
s[i+1][j]='';
i+=1;
}elseif(c=='L'&&j-1>=0){
s[i][j]=s[i][j-1];
s[i][j-1]='';
j-=1;
}elseif(c=='R'&&j+1<5){
s[i][j]=s[i][j+1];
s[i][j+1]='';
j+=1;
}elseif(isspace(c))continue;//防止空字符的干扰
elseflag2=1;//指令非法
}
getchar();//吸收指令行后的回车
if(!cnt)printf("Puzzle #%d:\n",++cnt);//按照格式输出
elseprintf("\nPuzzle #%d:\n",++cnt);
if(flag2){
printf("This puzzle has no final configuration.\n");