样例测试都过了,但交上去是wrong,求找错
#include<stdio.h> #include<string.h> struct{ int x,y,step; }queue[1000],e; int p[8][2]={2,1,2,-1,1,2,1,-2,-1,2,-1,-2,-2,1,-2,-1},vis[10][10]; char ch1[3],ch2[3]; int x1,y1,x2,y2,i; void bfs(void) { int x,y,start=0,tail=0,step; e.x=x1; e.y=y1; e.step=0; queue[start]=e; while(start<=tail) { x=queue[start].x; y=queue[start].y; step=queue[start].step; start++; for(i=0;i<8;i++) { e.x=x+p[i][0]; e.y=y+p[i][1]; e.step=step+1; if(e.x<1||e.x<1||e.y>8||e.y<1||vis[e.x][e.y]) continue; if(e.x==x2&&e.y==y2) { printf("To get from %s to %s takes %d knight moves.\n",ch1,ch2,e.step); } tail++; queue[tail]=e; vis[e.x][e.y]=1; } } } int main () { while(scanf("%s%s",ch1,ch2)!=EOF) { if(strcmp(ch1,ch2)==0) { printf("To get from %s to %s takes 0 knight moves.\n",ch1,ch2); continue; } x1=ch1[0]-'a'+1; y1=ch1[1]-'0'; x2=ch2[0]-'a'+1; y2=ch2[1]-'0'; memset(vis,0,sizeof(vis)); vis[x1][y1]=1; bfs(); } return 0; }
求改错啊!!!!!!