谜题
有一个5*5的网格,其中恰好有一个格子是空的,其他格子各有一个字母。一共有4种指令:A, B, L, R,分别表示把空格上、下、左、右的相邻字母移到空格中。输入初始网格和指令序列(以数字0结束),输出指令执行完毕后的网格。如果有非法指令,应输出“This puzzle has no final configuration.”。
#include "pch.h"
#include <iostream>
using namespace std;
void swap(char &x, char &y)
{
char temp;
temp = x;
x = y;
y = temp;
}
int main()
{
int r = 0, c = 0, i = 0, j = 0;
bool islegal = true;
char grid[6][6];
char s[105];
memset(grid, '\0', sizeof(grid));
memset(s, '\0', sizeof(s))