UVa 227-puzzle

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.