#include<stdio.h>
#include<string.h>
#include<stdlib.h>
#include<algorithm>
int case1 = 0;
int last = 1;
int main(){
while (1){
char p[5][7];
char buf[7];
int m, n, ilg = 1, first;
char c[1000];
for (int i = 0; i < 5; i++){
gets(buf);
if (buf[0] != '\0') strcpy(p[i], buf);
else i--;
if (strcmp(p[0], "Z") == 0) return 0;
for (int j = 0; j < 5; j++){
if (p[i][j] == ' '){
m = i;
n = j;
}
}
}
char ch;
for (int i = 0;; i++){
ch = getchar();
if (ch != '\n')
c[i] = ch;
else i--;
if (ch == '0'){
c[i + 1] = '\0';
break;
}
}
for (int k = 0; k<strlen(c); k++){
while (c[k] != '0')
{
if (c[k] == 'A'&&m - 1 > -1){
p[m][n] = p[m - 1][n];
p[m - 1][n] = ' ';
m--; break;
}
else if (c[k] == 'B'&&m + 1 < 5){
p[m][n] = p[m + 1][n];
p[m + 1][n] = ' ';
m++; break;
}
else if (c[k] == 'L'&&n - 1 > -1){
p[m][n] = p[m][n - 1];
p[m][n - 1] = ' ';
n--; break;
}
else if (c[k] == 'R'&&n + 1 < 5){
p[m][n] = p[m][n + 1];
p[m][n + 1] = ' ';
n++; break;
}
else{
ilg = 0;
break;
}
}
}
if (last) last = 0;
else printf("\n");
printf("Puzzle #%d:\n", ++case1);
if (ilg){
for (int i = 0; i < 5; i++){
first = 1;
for (int j = 0; j < 5; j++){
if (first) first = 0;
else printf(" ");
printf("%c", p[i][j]);
}
printf("\n");
}
}
else printf("This puzzle has no final configuration.\n");
memset(c, '\0', 1000 * sizeof(char));
}
return 0;
}
题目不难,就是输入输出麻烦。竟然因为This puzzle has no final configuration.少打了个final而wrong answer,坑了几个小时。。。。