版权声明:本人菜鸟一只,如文章有错误或您有高见,请不吝赐教 https://blog.csdn.net/qq_41138935/article/details/82590917
#include<iostream>
#include<cstring>
using namespace std;
//当前行列的位置
int row=2,col=1;
char arr[5][5]={
{'T','R','G','S','J'},
{'X','D','O','K','I'},
{'M',' ','V','L','N'},
{'W','P','A','B','E'},
{'U','O','H','C','F'}
};
int fa(){
if(row>0&&row<=4){
arr[row][col]=arr[row-1][col];
arr[row-1][col]=' ';
row-=1;
}else{
cout<<"This puzzle has no final configuration."<<endl;
return 0;
}
return 0;
}
int fb(){
if(row<4&&row>=0){
arr[row][col]=arr[row+1][col];
arr[row+1][col]=' ';
row+=1;
}else{
cout<<"This puzzle has no final configuration."<<endl;
return 0;
}
return 0;
}
int fl(){
if(col>0&&col<=4){
arr[row][col]=arr[row][col-1];
arr[row][col-1]=' ';
col-=1;
}else{
cout<<"This puzzle has no final configuration."<<endl;
return 0;
}
return 0;
}
int fr(){
if(col>=0&&col<4){
arr[row][col]=arr[row][col+1];
arr[row][col+1]=' ';
col+=1;
}else{
cout<<"This puzzle has no final configuration."<<endl;
return 0;
}
return 0;
}
int main(){
char a[100];
int i,j,k;
cin>>a;
int lena=strlen(a);
for(i=0;i<lena;i++){
switch(a[i]){
case 'A':fa();
break;
case 'a':fa();
break;
case 'B':fb();
break;
case 'b':fb();
break;
case 'L':fl();
break;
case 'l':fl();
break;
case 'R':fr();
break;
case 'r':fr();
break;
}
if(a[i]=='0')
break;
}
for(int i=0;i<5;i++){
for(int j=0;j<5;j++){
cout<<arr[i][j]<<"\t";
}
cout<<endl;
}
return 0;
}