有一些问题,例如string.h和stdio.h颜色不一样,还有map变量
#include<stdio.h>
#include<string.h>
struct
{
int x, y;
int p;
} line[20000];
int map[52][52];
int yes[4][52][52];
int main(void)
{
int i, j, k;
char tmpchar[6];
int x, y, x1, y1, x2, y2;
int to[4][2]={{1,3},{0,2},{1,3},{0,2}};
char word[4][6]={"east", "south", "west", "north"};
while(scanf("%d%d", &x, &y),(x!=0 && y!=0))
{
int point=0, now=1;
int flag=0;
memset(map, 0, sizeof(map));
memset(yes, 0, sizeof(yes));
for(i=1; i<=x; i++)
{
for(j=1; j<=y; j++)
{
scanf("%d", &map[i][j]);
for(k=0; k<4; k++)
{
yes[k][i][j]=map[i][j];
}
}
}
scanf("%d%d%d%d%s", &x1, &y1, &x2, &y2, tmpchar);
if(x1==x2 && y1==y2)
{
printf("0\n");
continue;
}
line[point].x = x1;
line[point].y = y1;
for(i=0; i<4; i++)
{
if(strcmp(word[i], tmpchar) == 0)
{
line[point].p = i;
break;
}
}
yes[line[point].p][x1][y1]=1;
while(point<now && now<19000)
{
for(i=0; i<2; i++)
{
if(!yes[to[line[point].p][i]][line[point].x][line[point].y])
{
line[now] = line[point];
line[now].p = to[line[point].p][i];
yes[line[now].p][line[point].x][line[point].y] = yes[line[point].p][line[point].x][line[point].y]+1;
now++;
}
}
switch(line[point].p)
{
case 0:
for(i=1+line[point].y, k=0; k<4 && i<y && (!map[line[point].x][i+1]) && (!map[line[point].x+1][i+1]); i++,k++)
{
if(!yes[line[point].p][line[point].x][i])
{
line[now] = line[point];
line[now].y = i;
yes[line[point].p][line[point].x][i] = yes[line[point].p][line[point].x][line[point].y]+1;
if(line[now].x == x2 && line[now].y == y2)
{
flag=1;
goto finish;
}
now++;
}
}
break;
case 1:
for(i=1+line[point].x, k=0; k<4 && i<x && (!map[i+1][line[point].y]) && (!map[i+1][line[point].y+1]); i++,k++)
{
if(!yes[line[point].p][i][line[point].y])
{
line[now] = line[point];
line[now].x = i;
yes[line[point].p][i][line[point].y] = yes[line[point].p][line[point].x][line[point].y]+1;
if(line[now].x == x2 && line[now].y == y2)
{
flag=1;
goto finish;
}
now++;
}
}
break;
case 2:
for(i=line[point].y-1, k=0; k<4 && i>0 && (!map[line[point].x][i]) && (!map[line[point].x+1][i]); i--,k++)
{
if(!yes[line[point].p][line[point].x][i])
{
line[now] = line[point];
line[now].y = i;
yes[line[point].p][line[point].x][i] = yes[line[point].p][line[point].x][line[point].y]+1;
if(line[now].x == x2 && line[now].y == y2)
{
flag=1;
goto finish;
}
now++;
}
}
break;
case 3:
for(i=line[point].x-1, k=0; k<4 && i>0 && (!map[i][line[point].y]) && (!map[i][line[point].y+1]); i--,k++)
{
if(!yes[line[point].p][i][line[point].y])
{
line[now] = line[point];
line[now].x = i;
yes[line[point].p][i][line[point].y] = yes[line[point].p][line[point].x][line[point].y]+1;
if(line[now].x == x2 && line[now].y == y2)
{
flag=1;
goto finish;
}
now++;
}
}
break;
} /* End of switch*/
point++;
}
finish:
if(flag)
{
printf("%d\n", yes[line[now].p][line[now].x][line[now].y]-1);
}
else
{
printf("-1\n");
}
}
return 0;
}