文档介绍:#include""
#include ""
#define maxlen 100
int length=0; //记录所走的步数
static int bx[8] = {2,1,-1,-2,-2,-1,1,2};
static int by[8] = {1,2,2,1,-1,-2,-2,-1};
typedef struct
{
int n,m; //n 记录行数,m 记录列数
int ch;
}node;
typedef struct //定义顺序队列类型
{
node data[maxlen];
int front;
int rear;
}Sequeue;
Sequeue *setqueue()
{
Sequeue *S;
S=(Sequeue *)malloc(sizeof(Sequeue));
S->front=0;
S->rear=0;
return S;
}
void add(Sequeue *S,int x,int y,int z) //入队函数
{
if(S->rear<maxlen-1 && S->rear>=0)
{
S->rear++;
S->data[S->rear].n=x;
S->data[S->rear].m=y;
S->data[S->rear].ch=z;
}
else printf("error\n");
}
void dele(Sequeue *s) //出队函数
{
if(s->front<s->rear)
s->front++;
else
printf("error\n");
}
void judge() //判断步数
{
Sequeue *S;
S=setqueue();
int x0,y0,x1,y1,x3,y3,i,j; int count[maxlen+100];int a=0; int step[maxlen][maxlen];
char xa,xb;
for( i=0;i<maxlen;i++)
{
S->data[i].ch=0;
}
printf("请输入骑士游历的起终点:\n");
scanf(" %c,%d %c,%d",&xa,&y0,&xb,&y1);
x0=xa-'a';
x1=xb-'a';
for( i=0;i<maxlen;i++)
for( j=0;j<maxlen;j++)
{
step[i][j]=0;
}
step[x0][y0]=1;
add(S,x0,y0,0);
while(S->front<S->rear)
{
node *p;
x0=S->data[S->front+1].n;
y0=S->data[S->front+1].m;
for(int i=0;i<8;i++)
{
x3=bx[i]+x0;
y3=by[i]+y0;