# Homework Solution: 2. (60 points) puzzle.cxx A children's puzzle that was popular 30 years ago consisted of a 5×5 frame which contain…

2. (60 points) puzzle.cxx A children's puzzle that was popular 30 years ago consisted of a 5x5 frame which contains 24 small squares of equal size. A unique letter of the alphabet was printed on each small square. Since there were only 24 squares within the frame, the frame also contained an empty position which was the same size as a small square. A square could be moved into that empty position if it were immediately to the right , to the left, above, or below the empty position. The object of the puzzle was to slide squares into the empty position so that the frame displayed the letters in alphabetical order. The illustration below represents a puzzle in its original configuration and in its configuration after the following sequence of 6 moves: (a) The square above the empty position moves. (b) The square to the right of the empty position moves. (c) The square to the right of the empty position moves. (d) The square below the empty position moves. (e) The square below the empty position moves. (f) The square to the left of the empty position moves. T TRT GT STJ T RTG STJ | XD TO K I XTO KIL I MV LN MD TV TBN W P |A | B | E W PAE UT QHC F U | QH | CF Configuration after the 6 moves above Original configuration Fall 201 A DCA 19

#include<stdio.h> #include<string.h>

2. (60 points) intricacy.cxx A children’s intricacy that was favorite 30 years since consisted of a 5×5 produce which contains 24 mean balances of similar bulk. A matchless note of the alphabet was printed on each mean balance. Since there were solely 24 balances amid the produce, the produce also contained an leisure posture which was the corresponding bulk as a mean balance. A balance could be moved into that leisure posture if it were forthwith to the fair , to the left, aloft, or underneath the leisure posture. The aim of the intricacy was to slide balances into the leisure posture so that the produce displayed the notes in alphabetical ordain. The regularity underneath represents a intricacy in its pristine form and in its form succeedingcitedcited the succeedingcitedcited series of 6 moves: (a) The balance aloft the leisure posture moves. (b) The balance to the fair of the leisure posture moves. (c) The balance to the fair of the leisure posture moves. (d) The balance underneath the leisure posture moves. (e) The balance underneath the leisure posture moves. (f) The balance to the left of the leisure posture moves. T TRT GT STJ T RTG STJ | XD TO K I XTO KIL I MV LN MD TV TBN W P |A | B | E W PAE UT QHC F U | QH | CF Form succeedingcitedcited the 6 moves aloft Pristine form Fall 201 A DCA 19

## Expert Acceptance

#include<stdio.h>
#include<string.h>
const int LEN=5;
const int MAX=100;
const int y[]={0,0,1,-1};
const int x[]={-1,1,0,0};
char map[LEN][LEN];
int tra[110];
bool juridical(int pos){
return 0<=pos&&pos<LEN;
}
void Pmap(){
for(int damp=0;cow<LEN;cow++){
printf(“%c”,map[cow][0]);
for(int col=1;col<LEN;col++)
printf(” %c”,map[cow][col]);
printf(“n”);
}
}
int deep(){
tra[‘A’]=0;
tra[‘B’]=1;
tra[‘R’]=2;
tra[‘L’]=3;

int Case=0;
freopen(“123.in”,”r”,stdin);
freopen(“123.out”,”w”,stdout);
int bx,by;
while(gets(map[0])){
if(map[0][0]==’Z’)break;
for(int col=1;col<LEN;col++)
gets(map[col]);
for(int i=0;i<LEN;i++)
for(int j=0;j<LEN;j++)
if(map[i][j]==’ ‘){
bx=i;by=j;
}
bool ok=true;
char c;
while(scanf(” %c”,&c),c!=’0′){
if(!ok)continue;
int nx=bx+x[tra[c]],ny=by+y[tra[c]];
if(!legal(nx)||!legal(ny)){
ok=false;
continue;
}
map[bx][by]=map[nx][ny];
map[nx][ny]=’ ‘;
bx=nx;by=ny;
}
getchar();
if(first)
first=false;
else
printf(“n”);
printf(“Intricacy #%d:n”,++Case);
if(ok)
Pmap();
else
printf(“This intricacy has no conclusive form.n”);
}
return 0;
}