uva227求教。
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
int main()
{
int act0=0,puzzle0=0,i,j,num=0,x,y,outrange=0,stop=0;
char act[1000],puzzle[5][5];
while(puzzle0==0)
{
if (act0==0)
{
gets(act);
if (act[0]=='Z')
{
puzzle0=1;
break;
}
else
{
for(i=0;i<5;i++)
{
puzzle[0][i]=act[i];
}
for (i=1;i<5;i++)
{
gets(puzzle[i]);
}
for(i=0;i<5;i++)
{
for(j=0;j<5;j++)
{
if(puzzle[i][j]==' ')
{
x=i;
y=j;
}
}
}
}
act0=1;
}
if (act0==1 && outrange==0)
{
gets(act);
for(i=0;i<strlen(act);i++)
{
if(act[i]=='L')
{
if (y-1<0)
{
if (act[strlen(act)-1]=='0')
stop=1;
outrange=1;
break;
}
else
{
puzzle[x][y]=puzzle[x][y-1];
puzzle[x][y-1]=' ';
y=y-1;
}
}
else if(act[i]=='R')
{
if (4<y+1)
{
if (act[strlen(act)-1]=='0')
stop=1;
outrange=1;
break;
}
else
{
puzzle[x][y]=puzzle[x][y+1];
puzzle[x][y+1]=' ';
y=y+1;
}
}
else if(act[i]=='A')
{
if (x-1<0)
{
if (act[strlen(act)-1]=='0')
stop=1;
outrange=1;
break;
}
else
{
puzzle[x][y]=puzzle[x-1][y];
puzzle[x-1][y]=' ';
x=x-1;
}
}
else if(act[i]=='B')
{
if (4<x+1)
{
if (act[strlen(act)-1]=='0')
stop=1;
outrange=1;
break;
}
else
{
puzzle[x][y]=puzzle[x+1][y];
puzzle[x+1][y]=' ';
x=x+1;
}
}
else if(act[i]=='0')
{
num++;
printf("\nPuzzle #%d:\n", num);
for (i=0;i<5;i++)
{
for (j=0;j<4;j++)
{
printf("%c ", puzzle[i][j]);
}
printf("%c\n", puzzle[i][4]);
}
act0=0;
}
}
}
if (act0==1 && outrange==1)
{
num++;
printf("\nPuzzle #%d:\n", num);
printf("This puzzle has no final configuration.\n");
while(stop==0)
{
char act[1000];
gets(act);
if (act[strlen(act)-1]=='0')
{
stop=1;
}
}
stop=0;
outrange=0;
act0=0;
}
}
return 0;
}
为什么有的数据会无限循环。。。
比如说
TRGSJ
XDOKI
M VLN
WPABE
UQHCF
ARRBBL0求大神