可不可以帮我看一下Uva227的代码,题目给的要求都达到了,但是vjudge上提交就是WA,试了很多次了,一直过不了
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
int main()
{
char puzzle[5][6],t;
int cnt=0,z=0;
while (1)
{
int i,j;
for (int x=0; x<5; x++)
{
for (int y=0; y<6; y++)
{
puzzle[x][y]=getchar();
if (puzzle[x][y]=='Z')
{
z++;
break;
}
if (puzzle[x][y]==' ')
{
i=x;
j=y;
}
if (puzzle[x][y]=='\n'&&y==4)
{
puzzle[x][y]=' ';
puzzle[x][y+1]='\n';
i=x;
j=y;
y++;
}
}
if (z)
break;
}
if (z)
break;
int flag=1,m=0;
cnt++;
char way[100]= {'\0'},n;
while ((n = getchar()) != '0')
{
way[m]=n;
m++;
}
int len=strlen(way);
for (int a=0; a<len; a++)
{
if (way[a]=='A')
{
if (i-1>=0)
{
t=puzzle[i-1][j];
puzzle[i-1][j]=puzzle[i][j];
puzzle[i][j]=t;
i-=1;
}
else
{
if (cnt!=1)
printf("\n");
printf("Puzzle #%d:\nThis puzzle has no final configuration.\n",cnt);
flag=0;
break;
}
}
if (way[a]=='B')
{
if (i+1<=4)
{
t=puzzle[i+1][j];
puzzle[i+1][j]=puzzle[i][j];
puzzle[i][j]=t;
i+=1;
}
else
{
if (cnt!=1)
printf("\n");
printf("Puzzle #%d:\nThis puzzle has no final configuration.\n",cnt);
flag=0;
break;
}
}
if (way[a]=='R')
{
if (j+1<=4)
{
t=puzzle[i][j+1];
puzzle[i][j+1]=puzzle[i][j];
puzzle[i][j]=t;
j+=1;
}
else
{
if (cnt!=1)
printf("\n");
printf("Puzzle #%d:\nThis puzzle has no final configuration.\n",cnt);
flag=0;
break;
}
}
if (way[a]=='L')
{
if (j-1>=0)
{
t=puzzle[i][j-1];
puzzle[i][j-1]=puzzle[i][j];
puzzle[i][j]=t;
j-=1;
}
else
{
if (cnt!=1)
printf("\n");
printf("Puzzle #%d:\nThis puzzle has no final configuration.\n",cnt);
flag=0;
break;
}
}
if(way[a]=='0')
break;
}
if (flag)
{
if (cnt!=1)
printf("\n");
printf("Puzzle #%d:\n",cnt);
for (int a=0; a<5; a++)
for (int b=0; b<5; b++)
{
if (b==0)
printf("%c",puzzle[a][b]);
else if (b==4)printf(" %c\n",puzzle[a][b]);
else printf(" %c",puzzle[a][b]);
}
}
setbuf(stdin, NULL);
}
}
谢谢各位!