UVA227老是WA,不知道错i在哪里!!求助

#include
#include
#include
#include
#define max 1999
typedef struct {
int x,y;
} pos;
int main() {
// freopen("in.txt","r",stdin);
// freopen("out.txt","w",stdout);
char t;
int pu=0,ok=0,m=0;
while(scanf("%c",&t)!=EOF) {

    if(t=='Z')break;
    pos sp;
    char s[5][6];
    s[0][0]=t;
    for(int i=1; i<5; i++) 
        scanf("%c",&s[0][i]);
    getchar();
    for(int i=0; i<5; i++)
        scanf("%c",&s[1][i]);
    getchar();
    for(int i=0; i<5; i++)
        scanf("%c",&s[2][i]);
    getchar();
    for(int i=0; i<5; i++)
        scanf("%c",&s[3][i]);
    getchar();
    for(int i=0; i<5; i++)
        scanf("%c",&s[4][i]);
    getchar();
    for(int i=0; i<5; i++)
        for(int j=0; j<5; j++)
            if(s[i][j]==' ') {
                sp.x=j;
                sp.y=i;
            }
    char ca;
    while(scanf("%c",&ca)&&ca!='0') {
        if(ca=='\n'||ca==' '||ca=='\t')continue;
        ok=0;

        if(ca=='A'&&sp.y-1>=0) {
            s[sp.y][sp.x]=s[sp.y-1][sp.x];
            s[sp.y-1][sp.x]=' ';
            sp.y-=1;
            ok=1;
        }
        if(ca=='B'&&sp.y+1<=4) {
            s[sp.y][sp.x]=s[sp.y+1][sp.x];
            s[sp.y+1][sp.x]=' ';
            sp.y+=1;
            ok=1;
        }
        if(ca=='R'&&sp.x+1<=4) {
            s[sp.y][sp.x]=s[sp.y][sp.x+1];
            s[sp.y][sp.x+1]=' ';
            sp.x+=1;
            ok=1;
        }
        if(ca=='L'&&sp.x-1>=0) {
            s[sp.y][sp.x]=s[sp.y][sp.x-1];
            s[sp.y][sp.x-1]=' ';
            sp.x-=1;
            ok=1;
        }
        if(ok==0) {
            while(scanf("%c",&ca)&&ca!='0');;
            break;
        }
    }
    getchar();
    if(m==1)
        printf("\n");
    else m=1;
    printf("Puzzle #%d:\n",++pu);
    if(ok==1) {
        for(int i=0,j=0; i<5; i++) {
            for( j=0; j<4; j++)
                printf("%c ",s[i][j]);
            printf("%c\n",s[i][j]);
        }
    } else
        printf("This puzzle has no final configuration.\n");

}
return 0;

}