uva 227 - Puzzle试了好多数据还是不知道哪里错了,老是WA
#include<stdio.h>
#include<string.h>
int main()
{
int i,j;
char a[12][12];
int maxn;
maxn=0;
while(gets(a[0]))
{
if(strcmp(a[0], "Z")==0)
return 0;
for(i=1;i<5;i++)
{
gets(a[i]);
}
int x,y;
x=10;y=10;
for(i=0;i<5;i++)
{
for (j=0;j<5;j++)
{
if(a[i][j]==' ')
{
x=i;y=j;
}
}
}
int tot;
tot=0;
int c;
while((c=getchar())!='0')
{
switch(c)
{
case 'A':if(x>0){a[x][y]=a[x-1][y];a[x-1][y]=' ';x-=1;} else {tot=1;}break;
case 'B':if(x<4){a[x][y]=a[x+1][y];a[x+1][y]=' ';x+=1;} else {tot=1;}break;
case 'L':if(y>0){a[x][y]=a[x][y-1];a[x][y-1]=' ';y-=1;} else {tot=1;}break;
case 'R':if(y<4){a[x][y]=a[x][y+1];a[x][y+1]=' ';y+=1;} else {tot=1;}break;
}
}
maxn++;
printf("Puzzle #%d:\n",maxn);
if(tot==1)
printf("This puzzle has no final configuration.\n\n");
else
{
for(i=0;i<5;i++)
{
for(j=0;j<5;j++)
{
if(j==4)
printf("%c",a[i][j]);
else
printf("%c ",a[i][j]);
}
printf("\n");
if(i==4)
printf("\n");
}
}
gets(a[0]);
}
return 0;
}
求大神指点。。。