Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include<stdio.h>
- #include<stdlib.h>
- int record_step=1000;
- int search(int x0,int y0,int x1,int y1,int count)
- {
- if(count<record_step)
- {
- if(x0==x1&&y0==y1)record_step=count;
- else if(x0<8&&x0>=0&&y0>0&&y0<=8)
- {
- search(x0+1,y0+2,x1,y1,count+1);
- search(x0+1,y0-2,x1,y1,count+1);
- search(x0-1,y0+2,x1,y1,count+1);
- search(x0-1,y0-2,x1,y1,count+1);
- search(x0+2,y0+1,x1,y1,count+1);
- search(x0-2,y0+1,x1,y1,count+1);
- search(x0+2,y0-1,x1,y1,count+1);
- search(x0-2,y0-1,x1,y1,count+1);
- }
- }
- }
- int main(i)
- {
- char word;
- int star[2],end[2];
- while(scanf("%c",&word)!=EOF)
- {
- star[0]=(int)(word-'a');
- scanf("%d %c%d",&star[1],&word,&end[1]);
- while(getchar()!='\n') continue;
- end[0]=(int)(word-'a');
- search(star[0],star[1],end[0],end[1],0);
- printf("To get from %c%d to %c%d takes %d knight moves.\n",star[0]+'a',star[1],end[0]+'a',end[1],record_step);
- record_step=1000;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement