Title: give you a matrix of letters, which have an empty space that gives you the rules of movement (a kind of puzzle game like a plane);
Ask whether the operation is legal and valid when the output moves after the result.
Description: Analog. Direct use of two-bit array simulation can be.
Analysis: The first question after the year (⊙v⊙).
#include <algorithm> #include <iostream> #include <cstdlib> #include <cstring> #include < Cstdio> #include <cmath>using namespace Std;char maps[5][7];char cmd[1001];int main () {int cases = 0;while (Gets ( Maps[0]) {if (maps[0][0] = = ' Z ') break;for (int i = 1; i < 5; + + i) gets (maps[i]); int b_x = 0,b_y = 0;for (int i = 0 ; I < 5; + + i) for (int j = 0; J < 5; + + j) if (maps[i][j] = = ") {b_x = I;b_y = J;break;} int count = 0;while (~scanf ("%c", &cmd[count])) if (Cmd[count]! = ' 0 ') Count ++;else break;cmd[count] = 0;getchar (); int Flag = 0,x = B_x,y = b_y;for (int i = 0; cmd[i]; + + i) {switch (Cmd[i]) {case ' A ': x = B_x-1;y = b_y; Break;case ' B ': x = b _x+1;y = b_y; Break;case ' L ': x = B_x;y = b_y-1; Break;case ' R ': x = B_x;y = b_y+1; break;} if (x < 0 | | x > 4 | | y < 0 | | y > 4) {flag = 1;break;} else {maps[b_x][b_y] = maps[x][y];maps[x][y] = "; b_x = x; b_y = y;}} if (cases + +) printf ("\ n");p rintf ("Puzzle #%d:\n", cases); if (flag) printf ("This Puzzle have no final configuration.\n "), else {for (int i = 0; i < 5; + + i) {printf ("%c ", maps[i][0]); for (int j = 1; J < 5; + + j) printf ("%c", Maps[i][j]);p rintf ("\ n");}} return 0;}
UVa 227-puzzle