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 childrens 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
    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

    Expert Answer

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

    2. (60 points) intricacy.cxx A childrens intricacy that was favorite 30 years since consisted of a 5x5 find which contains 24 little balances of correspondent largeness. A uncommon epistle of the alphabet was printed on each little balance. Since there were barely 24 balances among the find, the find as-well contained an space comcomsituation which was the identical largeness as a little balance. A balance could be moved into that space comcomsituation if it were straightway to the fit , to the left, overhead, or underneath the space composition. The motive of the intricacy was to slide balances into the space comcomsituation so that the find displayed the epistles in alphabetical direct. The regularity underneath represents a intricacy in its primordial contour and in its contour behind the subjoined prescribe of 6 moves: (a) The balance overhead the space comcomsituation moves. (b) The balance to the fit of the space comcomsituation moves. (c) The balance to the fit of the space comcomsituation moves. (d) The balance underneath the space comcomsituation moves. (e) The balance underneath the space comcomsituation moves. (f) The balance to the left of the space comcomsituation 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 Contour behind the 6 moves overhead Primordial contour Fall 201 A DCA 19

    2. (60 points) intricacy.cxx A children’s intricacy that was favorite 30 years since consisted of a 5×5 find which contains 24 little balances of correspondent largeness. A uncommon epistle of the alphabet was printed on each little balance. Since there were barely 24 balances among the find, the find as-well contained an space comcomsituation which was the identical largeness as a little balance. A balance could be moved into that space comcomsituation if it were straightway to the fit , to the left, overhead, or underneath the space composition. The motive of the intricacy was to slide balances into the space comcomsituation so that the find displayed the epistles in alphabetical direct. The regularity underneath represents a intricacy in its primordial contour and in its contour behind the subjoined prescribe of 6 moves: (a) The balance overhead the space comcomsituation moves. (b) The balance to the fit of the space comcomsituation moves. (c) The balance to the fit of the space comcomsituation moves. (d) The balance underneath the space comcomsituation moves. (e) The balance underneath the space comcomsituation moves. (f) The balance to the left of the space comcomsituation 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 Contour behind the 6 moves overhead Primordial contour Fall 201 A DCA 19

    Expert Reply

     

    #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 lawful(int pos){
    return 0<=pos&&pos<LEN;
    }
    void Pmap(){
    for(int deaden=0;cow<LEN;cow++){
    printf(“%c”,map[cow][0]);
    for(int col=1;col<LEN;col++)
    printf(” %c”,map[cow][col]);
    printf(“n”);
    }
    }
    int ocean(){
    tra[‘A’]=0;
    tra[‘B’]=1;
    tra[‘R’]=2;
    tra[‘L’]=3;

    bool chief=true;
    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 contour.n”);
    }
    return 0;
    }